340 likes | 418 Views
A Handy Data Structure. Space-Efficient Finger Search on Degree-Balanced Search Trees Guy Blelloch, Bruce Maggs, Maverick Woo. Rank. 1. 2. 45. 46. 63. Guibas et al., 1977. Totally-ordered list of unique keys. Finger points to a key---the “current” key Live demonstration coming…
E N D
A Handy Data Structure Space-Efficient Finger Search on Degree-Balanced Search Trees Guy Blelloch, Bruce Maggs, Maverick Woo
Rank 1 2 45 46 63 Guibas et al., 1977 Totally-ordered list of unique keys • Finger points to a key---the “current” key Live demonstration coming… (Trained professional; closed course; do not attempt!)
Rank 1 2 45 46 63 Finger Search FingerSearch(f, x): Starting from f, search for x, then move f to final destination. What Destination? • O(log d) time if finger rank changes by d
Rank 1 2 45 46 63 Finger Search Straightforward for sorted arrays… • O(log d) time if finger rank changes by d
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Balanced Search Trees BSTs can be seen as versatile sorted arrays • Can we do finger search on BSTs?
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Brown and Tarjan, 1979 Level-linked 2-3 Trees • Worst case bound • 5 pointers / key
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Tarjan and Van Wyk, 1988 Heterogeneous Finger Search Trees • Amortized bound • 2 pointers / key Inverted Spine
This Paper How to achieve the best of both worlds? (sort of) • Worst case bound • As few pointers as possible ?
Programming Perspective Suppose we are writing a search engine. • For each document, assign a unique number. • For each term, maintain a document list using a BST. • A query corresponds to taking intersections. To fit everything in main memory, node size matters.
Why Finger Search? Locality is Reality Finger search is theoretically appealing • Merging of two sorted list of m and n keys takestime, where m·n • Optimal in comparison-based models • Easy to extend to set intersection and union
In this paper… We introduce another way to support finger search • Assume 2 pointers per key (left, right) • Worst-case O(log d) bound • During runtime, maintain an O(log n)-size auxiliary data structure for an n-key degree-balanced BST • Insertions and deletions can be interleaved with finger searches in any order
In the rest of this talk… I will sketch how we designed our “hand” data structure. Two simplifying assumptions (for this talk only): • A full binary search tree • Finger will only go forward
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Special Case: In-order Walk If finger search is possible, then in-order walk must be worst-case O(1) time per step.
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 In-order Walk Need to walk up, e.g., at 5
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 In-order Walk Need to walk up, e.g., at 5 Classic: use a “Right Parent Stack” Rps
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 In-order Walk Need to walk down, e.g., at 8
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 In-order Walk Need to walk down, e.g., at 8 Can’t start chasing pointers after we’ve arrived at 8. Be Eager…
In-order Walk Chase them beforehand, one at a time! When we arrive at 8, 9 has already been “discovered”. 8 leaving 4 4 12 leaving 6 2 6 10 14 leaving 7 1 3 5 7 9 11 13 15
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 The Hand node spine x3 s3 x2 s2 Each node on the Rps maintainsa prefix of its right-left spine. (How long?) x1 s1 Rps
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 In-order Walk node spine x3 s3 x2 s2 1. Pop top cell and keep its spine s 2. Extend spine of new top cell 3. Prepend s to Rps x1 s1 Rps
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 56 1. Pop top cell and keep its spine s 2. Extend spine of new top cell 3. Prepend s to Rps Rps
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 56 1. Pop top cell and keep its spine s 2. Extend spine of new top cell 3. Prepend s to Rps Rps
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 56 1. Pop top cell and keep its spine s 2. Extend spine of new top cell 3. Prepend s to Rps Rps
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 At 6 1. Pop top cell and keep its spine s 2. Extend spine of new top cell 3. Prepend s to Rps Rps
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 67 1. Pop top cell and keep its spine s 2. Extend spine of new top cell 3. Prepend s to Rps Rps
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 67 1. Pop top cell and keep its spine s 2. Extend spine of new top cell 3. Prepend s to Rps Rps
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 67 1. Pop top cell and keep its spine s 2. Extend spine of new top cell 3. Prepend s to Rps Rps
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 At 7 1. Pop top cell and keep its spine s 2. Extend spine of new top cell 3. Prepend s to Rps Rps
8 4 12 2 6 10 14 1 3 5 7 9 11 13 15 Finger Search During an in-order walk, we know the future. But that’s not the case in finger search!
Surprise! Use the Hand! RP Rps s’ [atlas, peer) curr peer Length of Prefix s
Finger Destinations RP s’ [atlas, peer) curr peer s
Extensions and Future Work Refer to paper • “Real” degree-balanced search trees • Going backward • Interleaving with insertions and deletions Future Work • Experiments (especially on database prefetching)
Q & A Thank you for your attention.