Introduction to Random Binary Search Trees
Learn how to improve efficiency of Binary Search Tree using randomization.
We'll cover the following...
Here, we present a binary search tree structure that uses randomization to achieve expected time for all operations.
Consider the two binary search trees shown below in figure, each of which has nodes.
The one on the left is a list and the other is a perfectly balanced binary search tree. The one on the left has a height of and the one on the right has a height of three.
Imagine how these two trees could have been constructed. The one on
the left occurs if we start with an empty BinarySearchTree
and add the
sequence
No other sequence of additions will create this tree (as you can prove by
induction on n
). On the other hand, the tree on the right can be created
by the sequence
Other sequences work as well, including
and
In fact, there are addition sequences that generate the tree on the right and only one that generates the tree on the left.
The above example gives some anecdotal evidence that, if we choose a random permutation of , and add it into a binary search tree, then we are more likely to get a very balanced tree (the right side of the above illustration, than we are to get a very unbalanced tree (the left side of the above illustration).
We can formalize this notion by studying random binary search trees.
A random binary search tree of size n
is obtained in the following way: Take
a random permutation, , of the integers and add its
elements, one by one, into a BinarySearchTree
. By random permutation
we mean that each of the possible permutations (orderings) of
is equally likely, so that the probability of obtaining any particular permutation is .
Note that the values could be replaced by any ordered set of
n elements without changing any of the properties of the random binary
search tree. The element is simply standing in for the
element of rank x
in an ordered set of size n
.
Before we can present our main result about random binary search trees, we must take some time for a short digression to discuss a type of number that comes up frequently when studying randomized structures. For a non-negative integer, ...
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy