Optimal Binary Search Tree
Optimal Binary Search Tree
Search Tree
1.Preface
• The case of search are two situations, one is success, and the
other, without saying, is failure.
• We can get the first statement :
Success Failure
• Because we have probabilities of searches for each key and
each dummy key, we can determine the expected cost of a
search in a given binary search tree T.
• Let us assume that the actual cost of a search is the number of
nodes examined, i.e., the depth of the node found by the search
in T,plus1(Assuming root at depth 0).
• Then the expected cost of a search in T is : (The second
statement)
k1 k4 k1 k5
d0 d1
d0 d1 d5
k3 k5 k4
d2 d3 d4 d5 d4
k3
Figure (a)
i 0 1 2 3 4 5
d2 d3
Cost=
Node# Depth probability cost
Probability *
k1 1 0.15 0.30 (Depth+1)
k2 0 0.10 0.10
k3 2 0.05 0.15
k4 1 0.10 0.20
K5 2 0.20 0.60
d0 2 0.05 0.15
d1 2 0.10 0.30
d2 3 0.05 0.20
d3 3 0.05 0.20
d4 3 0.05 0.20
d5 3 0.10 0.40
• And the total cost = (0.30 + 0.10 + 0.15 + 0.20 + 0.60 + 0.15 +
0.30 + 0.20 + 0.20 + 0.20 + 0.40 ) = 2.80
• So Figure (a) costs 2.80 ,on another, the Figure (b) costs 2.75,
and that tree is really optimal.
• We can see the height of (b) is more than (a) ,
• The key k5 has the greatest search probability of any key, yet
the root of the OBST shown is k2.
Step1:The structure of an OBST