Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to choose RB tree, B-Tree or AVL tree?

As a programmer when should I consider using a RB tree, B- tree or an AVL tree? What are the key points that needs to be considered before deciding on the choice?

Can someone please explain with a scenario for each tree structure why it is chosen over others with reference to the key points?

like image 235
Palladin Avatar asked Oct 19 '09 15:10

Palladin


People also ask

Why do we prefer red-black tree over AVL tree?

Red black is more efficient.

Which is better AVL tree or red-black tree?

AVL trees provide faster lookups than Red-Black Trees because they are more strictly balanced.

Which is better AVL tree or B tree?

AVL trees are intended for in-memory use, where random access is relatively cheap. B-trees are better suited for disk-backed storage, because they group a larger number of keys into each node to minimize the number of seeks required by a read or write operation.

Is RB tree an AVL tree?

An RB tree is simply a variant of a B-tree and balancing is implemented differently than an AVL tree. AFIAK, an AVL tree has also O(1) rotation per insertion. For RB-tree and AVL - one insertion may have 1 or 0 rotations.


1 Answers

Take this with a pinch of salt:

B-tree when you're managing more than thousands of items and you're paging them from a disk or some slow storage medium.

RB tree when you're doing fairly frequent inserts, deletes and retrievals on the tree.

AVL tree when your inserts and deletes are infrequent relative to your retrievals.

like image 178
blwy10 Avatar answered Oct 15 '22 18:10

blwy10