previous | index | next

Balanced Trees and Search Efficiency

As our trace of in? showed, the time it takes to search a BST depends on the tree's height.

The height is minimized if it is balanced.

If a tree of n nodes is balanced, then its height is log2n.

Searching for an element in a balanced tree takes O(log n) time.

So, we want to minimize the height of a BST for searching.


previous | index | next