[prev] 9 [next]

Randomised BST Insertion

Effects of order of insertion on BST shape:
  • best case (for at-leaf insertion): keys inserted in pre-order
    (median key first, then median of lower half, median of upper half, etc.)
  • worst case: keys inserted in ascending/descending order
  • average case: keys inserted in random order  ⇒ O(log2 n)
Tree ADT has no control over order that keys are supplied.

Can the algorithm itself introduce some randomness?

In the hope that this randomness helps to balance the tree …