#### 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 on top to store the insertion-order sequence. I see that for small number of values, there is an a

it1352 0 2020-11-22

#### Red Black Tree deletion algorithm

From "Introduction to Algorithms 2nd edition" I got this deletion algorithm: /* RB-DELETE(T, z) 1 if left[z] = nil[T] or right[z] = nil[T] 2 then y ← z 3 else y ← TREE-SUCCESSOR(z) 4 if left[y] ≠ nil[T] 5 then x ← left[y] 6 else x ← right[y] 7 p[x] ← p[y] 8 if p[y] = nil[T] 9 then root[T] ←

it1352 2 2019-05-07

#### 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? Solution What's the main reason for choosing Red black trees instead of AVL trees? Both red-black trees and AVL trees are the most comm

it1352 1 2019-05-15

#### Red black tree black height property check

Given a RB Tree, I need to write an efficient algorithm that checks whether for each node, all paths from from the node to descendant leaves contain the same number of black nodes. i.e. returns a boolean if the property is true or false otherwise. Solution It wiil return the black height of the RB-tree. If the height is 0, the tree is an invalid

it1352 0 2019-05-07

#### Red black tree pseudocode redundancy

In introduction to Algorithms Third Edition they have a pseudocode implementation of red-black tree deletion. Here it is... RB-DELETE(T, z) y = z y-original-color = y.color if z.left == T.nil x = z.right RB-TRANSPLANT(T, z, z.right) elseif z.right == T.nil x = z.left RB-TRANSPLANT(T, z, z.left) e

it1352 0 2019-05-07

#### Problems with Promote() using the red-black tree implementation from The Tomes of Delphi

I am using the Red-Black tree implementation written by Julian Bucknall in his well-known book, The Tomes Of Delphi. Source code can be downloaded here, and I am using the code as-is in Delphi 2010, with modifications to TdBasics.pas to let it compile in a modern version of Delphi (mostly commenting most of it out - only a few definitions are requ

it1352 1 2019-05-15

#### How to tell whether a red-black tree can have X black nodes and Y red nodes or not

I have an exam next week in algorithms, and was given questions to prepare for it. One of these questions has me stumped though. "Can we draw a red-black tree with 7 black nodes and 10 red nodes? why?" It sounds like it could be answered quickly, but I can't get my mind around it. The CRLS gives us the maximum height of a RB tree with n internal

it1352 0 2019-05-07

#### Red Black Tree ~ 1 Child Deletes

Is it ever possible for a red parent node to have just ONE black child node? I have been playing around with the Red/Black Tree simulator online and I can't manage to get a case of this to happen. The reason behind asking this is I believe I have an unnecessary IF in my code... if (temp_node->color == BLACK && node->color == RED) {

it1352 0 2019-05-13

#### Red-Black Tree Height using Recursion

I have these following methods to get the height of a red black tree and this works (I send the root). Now my question is, how is this working? I have drawn a tree and have tried following this step by step for each recursion call but I can't pull it off. I know the general idea of what the code is doing, which is going through all the leaves and c

it1352 0 2019-05-13

#### Iterative Algorithm for Red-Black Tree

Can anyone please suggest me any pointer to an iterative algorithm for insertion and deletion into a Red-Black Tree? All the algorithms available in .Net/C# are based on recursion, which I can't trust for handling very large number of data (hence large number of recursion depth for insertion/deletion). Does anybody have one based on iteration? Not

it1352 0 2019-05-06