Questions tagged [red-black-tree]

A red-black tree is a type of self-balancing binary search tree, a data structure used in computing science, typically used to implement associative arrays.

From Wikipedia, Red–black tree:

A red-black tree is a special type of binary tree, used in computer science to organize pieces of comparable data, such as text fragments or numbers.

The leaf nodes of red-black trees do not contain data. These leaves need not be explicit in computer memory — a null child pointer can encode the fact that this child is a leaf — but it simplifies some algorithms for operating on red-black trees if the leaves really are explicit nodes. To save memory, sometimes a single sentinel node performs the role of all leaf nodes; all references from internal nodes to leaf nodes then point to the sentinel node.

Red-black trees, like all binary search trees, allow efficient in-order traversal in the fashion, Left-Root-Right, of their elements. The search-time results from the traversal from root to leaf, and therefore a balanced tree, having the least possible tree height, results in O(log n) search time.

588 questions
166
votes
6 answers

Red-black tree over AVL tree

AVL and Red-black trees are both self-balancing except Red and black color in the nodes. What's the main reason for choosing Red black trees instead of AVL trees? What are the applications of Red black trees?
suren
  • 1,744
  • 2
  • 12
  • 7
88
votes
4 answers

When to choose RB tree, B-Tree or AVL tree?

As a programmer when should I consider using a RB tree, B- tree or an AVL tree? What are the key points that needs to be considered before deciding on the choice? Can someone please explain with a scenario for each tree structure why it is chosen…
Palladin
  • 983
  • 1
  • 7
  • 10
84
votes
9 answers

Difference between red-black trees and AVL trees

Can someone please explain what the main differences between these two data structures are? I've been trying to find a source online that highlights the differences/similarities, but I haven't found anything too informative. In what cases would…
Bob John
  • 3,688
  • 14
  • 43
  • 57
75
votes
1 answer

Statistical performance of purely functional maps and sets

Given a data structure specification such as a purely functional map with known complexity bounds, one has to pick between several implementations. There is some folklore on how to pick the right one, for example Red-Black trees are considered to be…
57
votes
12 answers

Red-Black Trees

I've seen binary trees and binary searching mentioned in several books I've read lately, but as I'm still at the beginning of my studies in Computer Science, I've yet to take a class that's really dealt with algorithms and data structures in a…
wfarr
  • 1,563
  • 1
  • 13
  • 13
50
votes
2 answers

Red Black Tree versus B Tree

I have a project in which I have to achieve fast search, insert and delete operations on data ranging from megabytes to terabytes. I had been studying data structures of late and analyzing them. Being specific, I want to introduce 3 cases and ask…
swanar
  • 635
  • 1
  • 6
  • 10
49
votes
4 answers

Applications of red-black trees

What are the applications of red-black (RB) trees? Is there any application where only RB Trees can be used and no other data structures?
krackoder
  • 2,841
  • 7
  • 42
  • 51
48
votes
1 answer

What additional rotation is required for deletion from a Top-Down 2-3-4 Left-leaning Red Black tree?

I have been implementing an LLRB package that should be able to operate in either of the two modes, Bottom-Up 2-3 or Top-Down 2-3-4 described by Sedgewick (code - improved code, though dealing only with 2-3 trees here, thanks to RS for…
40
votes
7 answers

How to easily remember Red-Black Tree insert and delete?

It is quite easy to fully understand standard Binary Search Tree and its operations. Because of that understanding, I even don't need to remember the implementations of those insert, delete, search operations. I am learning Red-Black Tree now and I…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
31
votes
1 answer

Explanation of Red-Black tree based implementation of TreeMap in JAVA

I was going through the source code of TreeMap in JAVA. As per JAVA doc: A Red-Black tree based NavigableMap implementation. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time,…
Zeeshan
  • 11,851
  • 21
  • 73
  • 98
24
votes
6 answers

Are AVL Trees Evil?

I was reading the article from Steve Yegge about singletons. In it he mentions his teacher told him AVL Trees were evil. Is it just that red and black trees are a better solution?
Chap
  • 2,776
  • 24
  • 31
21
votes
4 answers

Concatenating red-black trees

The OCaml standard library has a wonderful Set implementation that uses a very efficient divide-and-conquer algorithm to compute the union of two sets. I believe it takes whole subtrees (not just single elements) from one set and inserts them into…
J D
  • 48,105
  • 13
  • 171
  • 274
21
votes
3 answers

Can anyone explain the deletion of Left-Lean-Red-Black tree clearly?

I am learning Left-Lean-Red-Black tree, from Prof.Robert Sedgewick http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf http://www.cs.princeton.edu/~rs/talks/LLRB/RedBlack.pdf While I got to understand the insert of the 2-3 tree and the LLRB, I have…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
20
votes
2 answers

How does a red-black tree work?

There are lots of questions around about red-black trees but none of them answer how they work. Why is it called red-black? How does this keep the tree balanced (thus increasing performance over an unbalanced normal binary search tree)? I'm just…
Pete
  • 10,651
  • 9
  • 52
  • 74
20
votes
6 answers

Hash tables v self-balancing search trees

I am curious to know what is the reasoning that could overweighs towards using a self-balancing tree technique to store items than using a hash table. I see that hash tables cannot maintain the insertion-order, but I could always use a linked list…
Vaibhav Bajpai
  • 16,374
  • 13
  • 54
  • 85
1
2 3
39 40