community
directory
books
authors
images
encyclopedia

Email:
Password:
Register

Knowledgerush Search

 

Google
  Web knowledgerush


Search for images of Red-black tree


Message boards   Post comment

Red-black tree

A red-black tree is a type of self-balancing binary search tree, a data structure used in computer science. It was invented in 1972 by Rudolf Bayer who called them "symmetric binary B-trees".

A red-black tree is a binary tree where each node has color as an extra attribute, either red or black. By constraining the coloring of the nodes it is ensured that the longest path from the root to a leaf is no longer than twice the length of the shortest path. This means that the tree is balanced. A red-black tree must satisfy these properties:

  • The root is black
  • All leaves are black.
  • Red nodes can only have black children.
  • All paths from a node to its leaves contain the same number of black nodes.

A common source of confusion with these properties is that they assume that all the leaves in the tree are nil leaves, which contain no data and serve merely to indicate where the tree ends. These nodes are often omitted in drawings, resulting in a tree which seems to contradict the above principles, but which in fact does not.

Red-black_tree_example.png

When nodes are removed or deleted, the tree must be transformed to keep these properties. This is done by repainting or rotating nodes.

A newly added node should be red by default. If the parent node is black, the tree is still valid. If both the parent node is red, and there exists a red uncle node, then they should be repainted black, and the grandparent node should be repainted red. (It may be necessary to continue repainting up to the root.) Otherwise, rotations are necessary. If the root ends up red, it should be repainted black.

See also: AVL tree, B-tree, splay tree

External links

Referenced By

Data Structures | Data structure | List of data structures | List of graph theory topics | List of mathematical topics (P-R)

 

Compose Your Message

Your Email Address or Pen Name (optional):
Subject:
Your Message:
 

 

 

 

 

 

This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "Red-black tree".

 

Contact UsPrivacy Statement & Terms of Use

 
Copyright © 1999-2003 Knowledgerush.com. All rights reserved.