Questions tagged [red-black-trees]
42 questions
12
votes
1 answer
Why use heap over red-black tree?
Heap supports insert operation in $O(\log n)$ time. And while heap supports remove min/max in $O(\log n)$ time, to remove any element (non min/max) heap takes $O(n)$ time.
However, red-black tree supports insert/remove both in $O(\log n)$ time. We…
Wonjoo Lee
- 123
- 1
- 5
5
votes
0 answers
Completeness of red-black tree operations
Red-black trees are defined to have the following invariants:
The nodes are in sorted order (it is a binary search tree).
The root is black, and leaves are black.
Every red node has black children.
Every path to the root passes through the same…
Mario Carneiro
- 541
- 2
- 14
3
votes
1 answer
I don't understand the case 4 of red-black tree deletion
I don't know why case 4 will resolve the issue of the double black of $x$ described in Introduction to algorithm p.329. I know case 1 is transformed into one of {2,3,4} case, and case 2 re-point $x$ to its parent node so it's approaching the root,…
Ning
- 307
- 1
- 13
2
votes
1 answer
Red-Black Tree deletion algorithm (CLRS, 3rd edition) : Deleting the root
I have been following the third edition of Introduction to Algorithms (by Cormen, Rivest, et al.), and have been studying the deletion algorithm for red-black trees. However, I am confounded at the moment while I am trying to delete a node from the…
nerdier.js
- 221
- 3
- 9
2
votes
0 answers
How to delete node from RB-tree
I need to implement my own red-black tree and I am stuck with deletion. I have found this book (Introduction to Algorithms) (p.222) and in the following code I can't understand this marked line.
Firstly, why do I need to do that if x.p is already…
Euler-Maskerony
- 33
- 3
2
votes
0 answers
Problem about variation of red-black trees
I got an exercise about a variation of RB trees but I am struggling to see how to solve it, therefore I'll be happy to hear your opinion about it.
The exercise is:
Let us define a binary search tree which we will call Red-Red-Black tree if it…
Yarin
- 285
- 1
- 8
2
votes
0 answers
How is red-black tree insertion more effective than avl tree insertion
I'm having trouble understanding why RB tree insertion is called more effective in all sources.
It's said that AVL trees require "more rotations" than RB trees, but from what I've learned I can't see it. AVL trees always require one or two…
Sviatozar Petrenko
- 41
- 2
2
votes
2 answers
Self-balancing BST supporting in-order-sequential multi-insertions / multi-deletions in logn+klogk time?
Given a self-balancing binary search tree of size $n$, I want to perform the following operations:
InsertInOrderSequentialBatch an ordered sequence of $k$ values (specialized $k \in \{2, 3, 4\}$ or generalized $k \in N $) which are guaranteed to be…
Warty
- 141
- 4
2
votes
1 answer
Prove that any subtree in a red-black tree has at least $2^{bh(x)} -1$ internal nodes
I'm reading the book Introduction to Algorithms. In the book, in the initial step of proving that a red-black tree with $n$ internal nodes has height at most $2\lg(n+1)$, they prove that any subtree rooted at any node $x$ in a red-black tree has at…
iRestMyCaseYourHonor
- 135
- 4
2
votes
1 answer
What would happen if we added this rule to red-black trees?
So, I know that a normal r-b tree has a height of O(logn). What would happen is we let a red node have a red child if its parent is black?
Would the height still be O(logn)? Would you have to have a totally different insertion scheme to maintain the…
Curious_CS_student
- 21
- 1
2
votes
0 answers
Red-black tree trinode restructuring after insertion and deletion
When performing an insertion/deletion on a red-black tree, how can be argued or proved that it requires at most one/two trinode restructuring(s) respectively?
My thoughts so far were: after inserting a node and two consecutive red nodes exist along…
PapaCode
- 21
- 1
2
votes
1 answer
Introduction To Algorithms 3rd Edition MIT Press: Red Black Tree insertion error in pseudo-code?
I'm implementing the algorithm on page 316 of the book Introduction to Algorithms. When I look at the pseudo-code, I feel that there is something wrong between line 10 to 14. I feel it's missing a check. There is a YouTube video explaining this…
Melvin Roest
- 183
- 7
2
votes
1 answer
Proof that a subtree of a red-black tree has no more than $\frac{3n}{4}$ nodes
I have a red-black tree with $n$ nodes, rooted at $x$. How can I prove or disprove that the number of nodes in any subtree of $x$ (including the root of the subtree) will never be greater than $\frac{3n}{4}$?
rtheunissen
- 203
- 1
- 7
1
vote
1 answer
Explain why the condition "NIL need to be black" exists in RED-BLACK tree definition
I know there's another question asking the same in this website, but answers to that question was not clear; it did not help me.
In this wikipedia page, the 2nd property says "All NIL nodes are considered black".
I want to know why that constraint…
Cinverse
- 113
- 2
1
vote
1 answer
Merge K BST of N elements in total into a single RBT in O(N log K) time
I have the following question to solve;
Given $K$ BST consisting of $N$ total elements, show how you can create a Red Black Tree in $O(N\log K)$ time.
I had the following idea but it falls on the last part of insertion into the red black tree;
Get…
Alon .G.
- 13
- 2