What are the Misunderstandings about Red-Black Tree Properties?

  • Thread starter Thread starter Joseph1739
  • Start date Start date
  • Tags Tags
    Properties Trees
Click For Summary

Discussion Overview

The discussion centers around the properties of red-black trees, particularly focusing on the requirement that all leaves are black. Participants explore the definitions of leaves and the implications of node colors within the structure of red-black trees, raising questions about the interpretation of these properties and their application.

Discussion Character

  • Debate/contested
  • Technical explanation

Main Points Raised

  • Some participants express confusion regarding the definition of leaves in red-black trees, questioning why certain nodes that are not leaves are also black.
  • It is noted that the property stating "all leaves are black" does not imply that all black nodes are leaves, highlighting a potential misunderstanding of the terminology.
  • Participants clarify that nodes such as 6, 22, and 27 have child nodes that are leaves marked NIL, which plays a role in the balancing of the tree.
  • There is a discussion about the implications of a node's color if it is not a leaf, with some participants suggesting that the color could be chosen at random, which is challenged by others who reference specific properties of red-black trees.
  • One participant emphasizes that the root node must be black and that the colors of child nodes of red nodes must also adhere to specific rules, indicating that not all colors can be chosen arbitrarily.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the interpretation of the properties of red-black trees, with multiple competing views presented regarding the definitions and implications of node colors and leaf status.

Contextual Notes

There are limitations in the discussion regarding the clarity of definitions and the assumptions made about what constitutes a leaf node in the context of red-black trees. The discussion also reflects varying levels of understanding of the properties and rules governing red-black trees.

Joseph1739
Messages
33
Reaction score
0
I don't understand the requirements for a red-black tree.
Using this photo:
https://upload.wikimedia.org/wikipedia/commons/6/66/Red-black_tree_example.svg

One of the 5 required properties is that all leaves are black.
A leaf is a node without a child, so that would only be 11 and 15 two links down from the root. So why is 1 and 25 black? They clearly have a child, so they are not leaves. Similarly, why is 6, 22, and 27 not black. They don't have children so they should be black.
 
Technology news on Phys.org
That all leaves are black does not imply that all black nodes are leaves.

6, 22, and 27 do have child nodes, which are leaves marked NIL. Whether a given red-black tree has explicit leaves does not affect their role in balancing the tree.
 
Integrand said:
That all leaves are black does not imply that all black nodes are leaves.

6, 22, and 27 do have child nodes, which are leaves marked NIL. Whether a given red-black tree has explicit leaves does not affect their role in balancing the tree.
So if a node is not a leaf, then the color can be chosen at random?
 
Joseph1739 said:
I don't understand the requirements for a red-black tree.
Using this photo:
https://upload.wikimedia.org/wikipedia/commons/6/66/Red-black_tree_example.svg

One of the 5 required properties is that all leaves are black.
A leaf is a node without a child, so that would only be 11 and 15 two links down from the root. So why is 1 and 25 black? They clearly have a child, so they are not leaves. Similarly, why is 6, 22, and 27 not black. They don't have children so they should be black.
What are the other rules?
 
Joseph1739 said:
One of the 5 required properties is that all leaves are black.
That all leaf nodes are black says something quite different than all black nodes are leaves. You apparently misread that property as the latter.

A leaf is a node without a child, so that would only be 11 and 15 two links down from the root. So why is 1 and 25 black? They clearly have a child, so they are not leaves. Similarly, why is 6, 22, and 27 not black. They don't have children so they should be black.
A leaf node in a binary search tree contains no data and has no children. The black nodes that contain 11 and 15, along with the red nodes that contain 6, 22, and 27 are not leaf nodes. Each of those nodes contains data (11, 15, 6, 22, and 27, respectively) and each has two children (all of which are leaf nodes).
Joseph1739 said:
So if a node is not a leaf, then the color can be chosen at random?
You need to look at the other properties. The root node is black, so it's color cannot be chosen at random. Both child nodes of a red node must be black, so the colors of those child nodes cannot be chosen at random. Finally, there's the balancing rule. Just because a tree obeys the basic properties of a binary search tree and first four properties of a red-black tree does not necessarily mean that it is a red-black tree.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 4 ·
Replies
4
Views
9K
  • · Replies 19 ·
Replies
19
Views
2K
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 15 ·
Replies
15
Views
6K
  • · Replies 10 ·
Replies
10
Views
4K