Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

grapes911

Moderator emeritus
Original poster
Jul 28, 2003
6,995
10
Citizens Bank Park
I have to implement a red-black tree in C++ for a project, but I don't know much about red-black trees. I've been trying to do my research for a few days now, but I still feel pretty lost.

1. Here is what I know:
a. They are binary trees.
b. Every node is either red or black.
c. The root is black.
d. Every path from the root to a leaf contains the same number of black nodes.
e. Red nodes can only have black children.
f. Every leaf is NULL and black.

2. Are this properties correct? Are there any other properties that I need to know?

3. I'm assuming it is more common to use an array rather than pointers. Is this true?

4. What make a node red or black? And what advantage do I get out of having red and black nodes.

5. Anyone know of any good sites with good examples?
 

Mitthrawnuruodo

Moderator emeritus
Mar 10, 2004
14,661
1,468
Bergen, Norway
Introductions to Algorithms has a whole chapter (13) dedicated to Red-Black threes, but I'm afraid I cannot type in those 30 pages here... :eek:

Maybe they have the book at your local public library. They don't provide code, but even better, the algorithm in a very easy-to-understand notation.

I don't think we ever implemented the algorithm in either of my C++ or Java courses...

Edit: On the other hand, Google is a friend, as ever: http://www.cs.fiu.edu/~weiss/dsaa_c++/code/ ;)
 

grapes911

Moderator emeritus
Original poster
Jul 28, 2003
6,995
10
Citizens Bank Park
Mitthrawnuruodo said:
Introductions to Algorithms has a whole chapter (13) dedicated to Red-Black threes, but I'm afraid I cannot type in those 30 pages here... :eek:

Maybe they have the book at your local public library. They don't provide code, but even better, the algorithm in a very easy-to-understand notation.

I don't think we ever implemented the algorithm in either of my C++ or Java courses...

Edit: On the other hand, Google is a friend, as ever: http://www.cs.fiu.edu/~weiss/dsaa_c++/code/ ;)
I have some books (none with very good examples). I'm having trouble just understanding the concept, let alone the code. Thank you though.

cait-sith said:
Is this for a university course?
Yep.
 

Mitthrawnuruodo

Moderator emeritus
Mar 10, 2004
14,661
1,468
Bergen, Norway
grapes911 said:
I have some books (none with very good examples). I'm having trouble just understanding the concept, let alone the code. Thank you though.
Well, that's the brilliant thing about the above mentioned Algorithm book. It explains how the trees work, in detail, with illustrations... :)
 

Voidness

macrumors 6502a
Aug 2, 2005
847
65
Null
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.