red-black-tree

In red-black trees is top-down deletion faster and more space efficient than bottom-up deletion?

Per this page http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_rbtree.aspx "Top-down deletion" is an implementation of a red-black tree node removal that pro-actively balances a tree by pushing a red node down through the tree so that the leaf node which is being removed is guaranteed to be red. Since the leaf node is gua...

Are AVL trees always a subset of red black trees?

I am searching for a proof that all AVL trees can be colored like a red-black tree? Can anyone give the proof? ...

Red Black Tree <Black Height> (Redraft)

/** The following function checks the red black tree black height * @param n the root node is inputed then a traversal is done to calculate the black-height * @return Return an error message / mesages informing the user whether or not the black height was maintained * @author Ferron Smith */ public static void getCount (SkaRedBlackTreeN...

Implementation of Red-Black Tree in C#

I'm looking for an implementation of a Red-Black Tree in C#, with the following features: Search, Insert and Delete in O(log n). Members type should be generic. Support in Comparer(T), for sorting T by different fields in it. Searching in the tree should be with the specific field, so it won't accept T, but it'll accept the field type ...

Starting with an empty tree, what is the complexity of inserting into Red Black Tree in big-O notation?

If I have 10 elements and starting with an empty tree, What is the complexity of inserting 10 elements into Red Black in big-O notation? Is it going to be more than O(log 10) because each time it inserts an element, it has to search for appropriate location for the element and performs a series of rotations between ancestor nodes and c...

a red black case question

I am trying to understand how red black trees work, assume the transition from first to the second at the picture, I get it this without any problem, after this according to teaching resources, I need to do a local fix on the red G node. So as a fix to the 2nd step, does G simply colored to black to maintain the red-black properties ?...

Find an algorithm in RBTREE in O(logn)

I need to find a data structure which I can do with the following actions: Build(S,k) - O(nlogn) Search(S,k) - O(logn) Insert(S,k) - O(logn) Delete(S,k) - O(logn) Decrease-Upto(s,k,d) - O(logn) - this method should subtract d(d>0) every node which is <=k The obvious first choise was RedBlackTree. However, I can't come to a solution ...

C# reference trouble...

Hi, I'm taking an algorithm course at the university, and for one of my projects I want to implement a red-black tree in C# (the implementation itself isn't the project, yet just something i decided to choose to help me out). My red-black tree should hold string keys, and the object i created for each node looks like this : class sRbTr...

Red-Black Tree Deleting Problem C#

Hey, I am trying to implement a red-black tree in C#. I already created an object called sRbTreeNode which has a String key, Color, Left, Right and Parent properties. I successfully managed implementing the methods Insert, InsertFixUp, LeftRotate, RightRotate, Delete, and now im having trouble with the method DeleteFixUp. DeleteFixUp i...

Red-Black trees - Erasing a node with two non-leaf children

Hi all, I've been implementing my own version of a red-black tree, mostly basing my algorithms from Wikipedia (http://en.wikipedia.org/wiki/Red-black_tree). Its fairly concise for the most part, but there's one part that I would like clarification on. When erasing a node from the tree that has 2 non-leaf (non-NULL) children, it says to...

red-black tree - construction

Recently, I have been going through search trees and I encountered red-black trees, the point confusing me is, In r-b tree, the root node should be black thats fine, now how will I decide whether the incoming node assumes red or black color. I have gone through the wiki article but have not found a solution for this. I might be wrong, b...

Interval tree algorithm that supports merging of intervals with no overlap

I'm looking for an interval tree algorithm similar to the red-black interval tree in CLR but that supports merging of intervals by default so that there are never any overlapping intervals. In other words if you had a tree containing two intervals [2,3] and [5,6] and you added the interval [4,4], the result would be a tree containing ju...

Why can't RB-Tree be a list?

Hey everyone. I have a problem with the rb-trees. according to wikipedia, rb-tree needs to follow the following: A node is either red or black. The root is black. (This rule is used in some definitions and not others. Since the root can always be changed from red to black but not necessarily vice-versa this rule has little effect on a...

Guidelines to an Iterator Class

Hi, I have a Red Black tree implemented in c++. It supports the functionality of a STL map. Tree nodes contain keys and the values mapped. I want to write an iterator class for this, but I'm stuck with how to do it. Should I make it an inner class of the Tree class? Can anyone give me some guidelines on how to write it + some resources...

CompareTo may return 0, alternative to TreeSet/TreeMap

I need a sorted set of objects and am currently using the TreeSet. My problem is that the compareTo of the objects will often return 0, meaning the order of those two objects is to be left unchanged. TreeMap (used by TreeSet by default) will then regard them as the same object, which is not true. What alternative to TreeMap can I use? ...

Hash Table v Self-Balancing Search Tree

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, th...

Red Black Tree for Sorting

The worst-case running time of insertion on a red-black tree is O(lg n) and if I perform a in-order walk on the tree, I essentially visit each node, so the total worst-case runtime to print the sorted collection would be O(n lg n) I am curious, why are red-black trees not preferred for sorting over quick sort (whose average-case running...

Red-black tree - how to rotate if root is the grandparent?

I am working on writing red-black tree myself. But when I test the rotation that involves root to be rotated, somewhat it loses reference. Tree structure: 45 / \ 40x 70 / \ / 7 41 50 / \ 6 39 The rotate logic says: "Rotate with 45(root) as top, in...

Red-black tree - How to find the node's parent?

In red-black tree, when rotate, you need to know who is the parent of particular node. However, the node only has reference to either right or left child. I was thinking to give a node instance variable "parent" but just for this reason I don't think it is worth doing so and also it would be too complicated to change parent reference p...

Computational complexity of TreeSet operations in Java?

Hello there. I am trying to clear up some things regarding complexity in some of the operations of TreeSet. On the javadoc it says: "This implementation provides guaranteed log(n) time cost for the basic operations (add, remove and contains)." So far so good. My question is what happens on addAll(), removeAll() etc. Here t...