1 / 14

O ptimal B inary S earch T ree

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.

Download Presentation

O ptimal B inary S earch T ree

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Optimal Binary Search Tree

  2. Optimal(理想) + Binary (二元 ) OBST + = Search (搜尋) + Tree (樹)

  3. 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.

  4. 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

  5. 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.

  6. APPLE dummy keys (d0,d1,…,dn) Bird Egg Keys (k1,k2,..kn) Grape Cat Dog Fish

  7. 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.

  8. elements • kn = key • pn = probability of searching kn • dn = dummy key • qn = probability of searching dn

  9. 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)

  10. 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)

  11. Example#1 K2 K2 K1 K5 K1 K4 d0 d1 d5 d0 K4 d1 K5 K3 d2 d3 d4 d5 K3 d4 d2 d3

  12. 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

  13. 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

  14. 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

More Related