TooMuchIsInteresting
TooMuchIsInteresting

Reputation: 111

how do I balance my binary tree

I already have a working binary tree database. Unfortunately, it needs to have the ability to balance itself. I don't want to rewrite the whole thing, I just want to include a function that will balance the tree. Any algorithms or ideas?

Upvotes: 1

Views: 3518

Answers (4)

Navaneeth K N
Navaneeth K N

Reputation: 15501

AVL and Red-Black trees are balanced binary trees. I have an implementation of AVL trees. Look here. It supports insertion and search. Deletion is not implemented yet.

Upvotes: 1

Arun
Arun

Reputation: 20383

I have found the Stanford libavl tutorial quite helpful.

Check out the examples in AVL tree wiki.

Also, try to play with the AVL tree animations available in the web, such as

Upvotes: 2

Aman Jain
Aman Jain

Reputation: 11317

AVL and RedBlack trees are self balancing trees. You can traverse your original tree and insert the nodes in these trees. Afterwards you can keep the new tree and discard your original tree.

Upvotes: 2

Anonymous
Anonymous

Reputation: 1297

look for balanced trees like avl red black

Upvotes: 0

Related Questions