140 likes | 252 Views
O ptimal B inary S earch T ree. O ptimal ( 理想 ). +. B inary ( 二元 ). OBST. +. =. S earch ( 搜尋 ). +. T ree ( 樹 ). 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.
E N D
Optimal(理想) + Binary (二元 ) OBST + = Search (搜尋) + Tree (樹)
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 dummy keys (d0,d1,…,dn) Bird Egg Keys (k1,k2,..kn) Grape Cat Dog Fish
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
Usefulstatement 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)
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 K2 K2 K1 K5 K1 K4 d0 d1 d5 d0 K4 d1 K5 K3 d2 d3 d4 d5 K3 d4 d2 d3
K1=2*0.15=0.3 K2=1*0.1 =0.1 K3=3*0.05=0.15 K4=2*0.1 =0.2 K5=3*0.2 =0.6 d0=3*0.05 =0.15 d1=3*0.1 =0.3 d2=4*0.05 =0.2 d3=4*0.05 =0.2 d4=4*0.05 =0.2 d5=4*0.1 =0.4 Cost=Probability * (Depth+1) K2 K4 K1 d0 d1 K5 K3 d2 d3 d4 d5 all cost=2.8
K2 K1=2*0.15 =0.3 K2=1*0.1 =0.1 K3=4*0.05 =0.2 K4=3*0.1 =0.3 K5=2*0.2 =0.4 d0=3*0.05 =0.15 d1=3*0.1 =0.3 d2=5*0.05 =0.25 d3=5*0.05 =0.25 d4=4*0.05 =0.2 d5=3*0.1 =0.3 Cost=Probability * (Depth+1) K1 K5 d0 d1 K4 d5 d4 K3 d2 d3 all cost=2.75
Picture#1=2.8 Picture#2=2.75 SO Picture#1cost more than Picture#2 Picture#2 is better. The depth of Picture#1 is 3 The depth of Picture#2 is 4