1 / 20

Order statistics a dynamic version

Order statistics a dynamic version. rank and select. The dictionary ADT. Insert ( x,D ) Delete ( x,D ) Find ( x,D ): Returns a pointer to x if x ∊ D, and a pointer to the successor or predecessor of x if x is not in D. Suppose we want to add to the dictionary ADT.

khoi
Download Presentation

Order statistics a dynamic version

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. Order statistics a dynamic version rank and select

  2. The dictionary ADT • Insert(x,D) • Delete(x,D) • Find(x,D): Returns a pointer to x if x ∊ D, and a pointer to the successor or predecessor of x if x is not in D

  3. Suppose we want to add to the dictionary ADT • Select(k,D): Returns the kthlargestelement in the dictionary: An element x such that k-1 elements are smaller than x

  4. Select(5,D) 89 90 19 20 21 4 26 34 67 70 73 77

  5. Select(5,D) 89 90 19 20 21 4 26 34 67 70 73 77

  6. Can we still use a red-black tree ? 4 19 20 21 26 34 67 70 73 77 89 90

  7. For each node v store # of leaves in the subtree of v 12 4 8 4 2 2 4 2 2 2 2 4 19 20 21 26 34 67 70 73 77 89 90

  8. Select(7,T) 12 4 8 4 2 2 4 2 2 2 2 4 19 20 21 26 34 67 70 73 77 89 90

  9. Select(7,T) 12 Select(3, ) 4 8 4 2 2 4 2 2 2 2 4 19 20 21 26 34 67 70 73 77 89 90

  10. Select(7,T) 12 4 8 Select(3, ) 4 2 2 4 2 2 2 2 4 19 20 21 26 34 67 70 73 77 89 90

  11. Select(7,T) 12 4 8 4 2 2 4 Select(1,) 2 2 2 2 4 19 20 21 26 34 67 70 73 77 89 90

  12. Select(i,T) Select(i,T): Select(i,root(T)) Select(k,v): if v is a leaf thenifk = 1then return velse error if k ≤ (v.left).sizethen return Select(k,v.left)else return Select(k – (v.left).size),v.right) O(logn) worst case time

  13. Rank(x,T) • Return the index of x in T

  14. Rank(x,T) x Need to return 9

  15. 12 4 8 4 2 2 4 2 2 2 2 4 19 20 21 26 34 67 70 73 77 89 90 x Sum up the sizes of the subtrees to the left of the path

  16. Insertion and deletions • Consider insertion, deletion is similar

  17. Insert 12 8 4 2

  18. Insert (cont) 13 9 5 3 2

  19. Easy to maintain through rotations x y <===> y A C x A B C B size(x) ← size(B) + size(C) size(y) ← size(A) + size(x)

  20. Summary • Insertion and deletion and other dictionary operations still take O(log n) time

More Related