Upload
isaak-vile
View
231
Download
0
Embed Size (px)
Citation preview
Optimal Binary
Search Tree
Optimal( 理想 )
Binary ( 二元 )
Search ( 搜尋 )
Tree ( 樹 )
OBST
+
+
+
=
Preface of OBST It is one special kind of advanced tree. It focus on how to reduce the cost of the
search of the BST. It may not have the lowest height. It needs 3 tables to record.
Purpose
In order to promote the efficiency of the search , we can let the cost of the search minimum or mean the average of compare minimum
It has n keys in sorted order (representation k1,k2,…,kn ) ( k1<k2<…<kn)
some searches may be for values not in ki, so we also have n+1 “dummy keys” d0,d1,…,dn representating not in ki.
d0 = all values < k1.
dn = all values > kn.
APPLE
Bird
Cat Dog
Egg
Fish Grape
dummy keys (d0,d1,…,dn)
Keys(k1,k2,..kn)
For each key ki, a pi which means the probability searching for ki.
For each key di, a qi which means the probability searching for di.
elements kn = key
pn = probability of searching kn
dn = dummy key
qn = probability of searching dn
Success probability = (i=1~n) ∑ pi
Failure probability = (i=0~n) ∑ qi
(i=1~n) ∑ pi + (i=0~n) ∑ qi = 1
Success cost = (i=1~n) ∑ pi * (depth(ki)+1)
Failure cost= (i=0~n) ∑ qi * (depth(di)+1)
Useful statement
E[search cost in ] = Success+ Failure
=(i=1~n) ∑ pi * (depth(ki)+1)+(i=0~n) ∑ qi * (depth(di)+1)
= (i=1~n) ∑ pi+(i=0~n) ∑ qi
+(i=1~n) ∑ pi * depth(ki)+(i=0~n) ∑ qi * depth(di)
= 1+(i=1~n) ∑ pi * depth(ki)+(i=0~n) ∑ qi * depth(di)
Example#1
i 0 1 2 3 4 5
pi 0.15
0.10.05
0.10.2
qi0.05
0.1
0.05
0.05
0.05
0.1
K1 K1
K2 K2
K3
K3
K4
K5K4
K5d0d0
d1
d2 d3 d4 d5
d1
d2 d3
d4
d5
K2
d0
i 0 1 2 3 4 5
pi 0.15
0.10.05
0.1 0.2
qi0.05
0.10.05
0.05
0.05
0.1
K1=2*0.15=0.3K2=1*0.1 =0.1K3=3*0.05=0.15
K4=2*0.1 =0.2K5=3*0.2 =0.6d0=3*0.05=0.15
d1=3*0.1 =0.3d2=4*0.05=0.2d3=4*0.05=0.2d4=4*0.05=0.2d5=4*0.1 =0.4
K4K1
K3 K5d1
d2 d5d4d3
Cost=Probability * (Depth+1)
all cost=2.8
i 0 1 2 3 4 5
pi 0.15
0.10.05
0.1 0.2
qi0.05
0.10.05
0.05
0.05
0.1
K1=2*0.15=0.3K2=1*0.1 =0.1K3=4*0.05=0.2K4=3*0.1 =0.3K5=2*0.2 =0.4d0=3*0.05=0.15
d1=3*0.1 =0.3d2=5*0.05=0.25
d3=5*0.05=0.25
d4=4*0.05=0.2d5=3*0.1 =0.3
Cost=Probability * (Depth+1)
K1
K2
K5
K4
K3
d0 d1 d5
d4
d2 d3
all cost=2.75
Picture#1=2.8
Picture#2=2.75
SO
Picture#1 cost more than Picture#2
Picture#2 is better.
The depth of Picture#1 is 3
The depth of Picture#2 is 4