Results 1 to 5 of 5
Thread: Red/Black Trees
- 12-11-2010, 08:06 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 44
- Rep Power
- 0
Red/Black Trees
This is end of chapter review excercise i am doing on my own to practice. I want to know if this is a valid representation of a Red/black Trees:
rules of a red black tree:
a) root has to be black
b) all children of a red node are black
c) Every path from root to a leaf contains has same number of a black nodes
so prob. is start with empty red/black tree:
insert(40); insert(25); insert(10); insert(5); insert(1); insert(45); insert(50);
my representation of this is (after re-balancing and changing colors)
i believe this is correct but just need verification to ensure my practice answer is correct (no solutions provided in book. This IS NOT DUE for homework just practicing for my final).Java Code:45 - black / \ 40 - red 50 - black / / 5-black 25 - red / \ 1-red 10 - red
After creating tree i have 2 more things to do: remove(40); remove(25)
again my implementation after rebalancing and changing colors:
thanks.Java Code:45 - black / \ 5-blk 50-blk / / 1-red 10 - red
- 12-11-2010, 11:11 PM #2
Member
- Join Date
- Nov 2010
- Posts
- 44
- Rep Power
- 0
- i am sure someone here can verify this ;)
- 12-12-2010, 12:30 AM #3
Try this:
Red/Black Tree Demo
- 12-12-2010, 12:45 AM #4
Member
- Join Date
- Nov 2010
- Posts
- 44
- Rep Power
- 0
thanks for the link; its pretty awesome :D
it came up with
which is different from my ending resultJava Code:45 -black / \ 5 - black 50-black / \ 1-red 10-red
i understand how red/back trees are constructed. What i need to know is that is my answer correct even though it varies from the demo output(i feel mine is correct because it doesn't violate any rules of red/black trees). And that is really what i needed someone to verify for me as i know there are multiple ways to do same thing.Java Code:45 - black / \ 5-blk 50-blk / / 1-red 10 - red
still thanks though.
oh and if someone needs to see demo for AVL Trees, go here:
http://www.site.uottawa.ca/~stan/csi...ts/avl/BT.htmlLast edited by f1gh; 12-12-2010 at 01:13 AM. Reason: posted link for avl trees.
- 12-12-2010, 02:30 AM #5
Yeah no problem, been too long since I implemented a RB tree form me to say comfortably, but since you can follow the rules and sometimes shift either right or left depending on how you coded, you could in theory get different results. However, I remember in my class back in the day, there was only one result, perhaps because we tested based on the specific algorithm used in our text?
Similar Threads
-
red black tree
By ahmakki in forum New To JavaReplies: 1Last Post: 03-21-2010, 06:49 AM -
Help required for black berry app development
By khadaree in forum CLDC and MIDPReplies: 0Last Post: 03-08-2010, 11:04 AM -
Red Black tree insertion
By unicorn in forum New To JavaReplies: 16Last Post: 11-03-2009, 05:46 PM -
Why this image background is black ?
By samson in forum Java 2DReplies: 1Last Post: 07-17-2007, 04:24 AM -
Implementing a red-black tree in java
By baltazar in forum New To JavaReplies: 1Last Post: 07-13-2007, 08:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks