Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing a balanced binary search tree? [closed]

I have implemented a binary search tree and I want to add more functionality in its insertion function to make it a self-balancing tree. I am coding in C#.

Can anybody please suggest me good tutorials or links on this? I did some searches and found some links, but none of them were descriptive enough.

Thanks.

like image 364
Lost Avatar asked Jul 24 '11 08:07

Lost


1 Answers

There are a great many algorithms for self-balancing search trees, many of which are complex and others of which are quite straightforward (albeit, with some caveats).

The book "Introduction to Algorithms, Second Edition" by Cormen, Leisserson, Rivest, and Stein is an excellent introduction to algorithms and covers red/black trees very well. It's also a great book in general on algorithms and data structures.

If you're interested in using splay trees, which are extremely fast and actually quite easy to implement, the original paper on the data structure is very accessible. On top of that, it includes a proof of all the runtime bounds.

The treap is a simple randomized balanced binary search tree that can be implemented quite easily once you know how to implement tree rotations. Tree rotations are also used in splay trees as well, and so it might be worth investigating.

For AVL trees, this lecture seems to be a good resource.

Hope this helps!

like image 110
templatetypedef Avatar answered Nov 15 '22 21:11

templatetypedef