1 / 89

Thy Shalt Come To The TGIW

Thy Shalt Come To The TGIW. From: shuchi@cs.cmu.edu Subject: TGIW When: Tonight, 6:00pm Where: WeH 7220

shea
Download Presentation

Thy Shalt Come To The TGIW

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. Thy Shalt Come To The TGIW From: shuchi@cs.cmu.edu Subject: TGIW When: Tonight, 6:00pm Where: WeH 7220 Nikhil will be talking about his work on Online Scheduling at this week's TGIW. This is joint work with Kedar, Jochen and Amitabh. The schedule and abstract are given below. First years are especially encouraged to attend. […]

  2. Back From The Future Efficient Finger SearchUsing Eager Walk

  3. Color Color Color Color Color Color Color Color Color Color Color List of Colors

  4. Important Terms/Phrases • Catenable (Cannibal on Halloween…) • File • “n” (no “m”) • Nine (no “line”) • Node • Theory • Three (“free” lunch?)

  5. Set Intersection BST: Balanced Search Tree • You have two setsA := {x1, x2, …, xa}, B := {y1, y2, …, yb} • You represent them as BSTs TA and TB • Give an algorithm to find A Å B

  6. Easy Solution WLOG assume a ¸ b. For each yj2 TB, ask if yj2 TA. O(b log a) time Is this optimal?

  7. 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 An Insight A := {1,2,3, …, 15}B := {1,3,10,11} Decisions at “top” mostly the same Show More

  8. 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Enters Finger Search fx: finger on key x FSearch(fx, y): Given a finger fx, return finger fy in O(log d) time, where d is the distance between x and y in the sorted order. If y 2 T, return fy+ for smallesty+ 2 T

  9. 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Why Bother Finger Searching? Another simple intersection algorithm: f = f0/* finger on conceptual “y0” */For i = 1 to b /* in-order walk TB */ f = FSearchA(f, yi) if f on yi then print yi Next i

  10. Running Time Analysis Do b finger searches in TA. Suppose distances are d1, d2, …, db. Know åi di· a Total time = O(log d1 + log d2 + … + log db) Time maximized when all di’s are equal, so let di = a/b. Total time = O(b log(a/b))

  11. Initialization Termination Condition Increment De-referencing InOrder(tree) := Iterator it; for(it.init(tree); it.hasMore(); it++) {// print (*it).node } Iterators

  12. Special Case In-orderWalk

  13. 8 4 12 <6 >6 2 6 10 14 1 3 5 7 9 11 13 15 Complete Binary Search Tree

  14. Node Size Node needs at least three machine words struct Node { int key; Node *left, *right; };

  15. Running Time Analysis InOrder(node) := If(node != Nil) { InOrder(node.left); // print node.key InOrder(node.right); } How about time between two consecutive outputs?

  16. Running Time Analysis InOrder(node) := If(node != Nil) { InOrder(node.left); // print node.key InOrder(node.right); } Amortized O(1) per node

  17. 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Space Requirement O(log n) activation records on the program stack InOrder(node) := If(node != Nil) { InOrder(node.left); // print node.key InOrder(node.right); }

  18. So Far So Good? #keys #pointers

  19. 8 4 4 12 12 2 2 6 6 10 10 14 14 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 I wonder... Worst case O(1)?

  20. 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Why Bother? Fast sequentialaccess slow slow slow

  21. 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Let's Trade Node needs 2 extra words Neighborpointers

  22. 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 / Faster Insertion Doubled node)Doubled space Indexed Sequence (B+ Trees)

  23. Oh Well...

  24. 8 4 Right Parentof 6 12 2 6 10 14 1 3 5 7 9 11 13 15 Two Terms Right parent is first ancestorto the right

  25. Two Terms h 12, 10, 9 i is “Left spine” of 12 “RL spine” of 8 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15

  26. 8 4 12 O(1) time? 2 6 10 14 1 3 5 7 9 11 13 15 Our Idea Pre-compute right child’s left spine How? Discover nodes step-by-step

  27. 2 4 8 Our "Hand" Iterator This Hand isnot valid. Justfor illustration. Stack of (Node *node, Stack *spine) Right Parent Stack (n,s) (n,s) (n,s)

  28. ptr within stack ptr to spine current node parent node left spine node Stack of Stacks (n,s) 8 Right Parent Stack (RPS) 4 12 2 6 10 14 1 3 5 7 9 11 13 15

  29. 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Initialization Left spine of root maintained during key insertions RPS

  30. 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 De-reference Peek top of stack RPS

  31. 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Termination Is stack empty? RPS

  32. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Increment Three easy steps 1. Pop top cell andkeep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  33. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 1  2 Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  34. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 1  2 Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  35. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 1  2 Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  36. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Hand on 2 RPS

  37. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 2  3 SS Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  38. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 2  3 SS Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  39. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 2  3 Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  40. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 3  4 Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  41. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 3  4 Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  42. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 3  4 Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  43. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 4  5 SS Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  44. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 4  5 SS Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  45. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 4  5 Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS RPS

  46. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Hand on 5 RPS

  47. Checkpoint Do you understand how to this algorithm manipulate the Hand?

  48. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Pop Quiz This is the Handon 5, so what isthe Hand on 6?

  49. ptr within stack ptr to spine current node parent node left spine node 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Pop Quiz Three easy steps 1. Pop top cell and keep its spine (SS) 2. Extend spine of new top cell 3. Prepend SS to RPS

  50. ptr within stack ptr to spine current node parent node left spine node Answer 5  6 8 4 12 2 6 10 14 1 3 5 7 9 11 13 15

More Related