A Handy Data Structure

34
1 A Handy Data Structure A Handy Data Structure Space-Efficient Finger Search on Degree-Balanced Search Trees Guy Blelloch, Bruce Maggs, Maverick Woo

description

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… - PowerPoint PPT Presentation

Transcript of A Handy Data Structure

Page 1: A Handy Data Structure

1

A Handy Data StructureA Handy Data Structure

Space-Efficient Finger Search on

Degree-Balanced Search Trees

Guy Blelloch, Bruce Maggs, Maverick Woo

Page 2: A Handy Data Structure

2

Guibas et al., 1977Guibas et al., 1977Guibas et al., 1977Guibas et al., 1977

Finger points to a key---the “current” key

Live demonstration coming…(Trained professional; closed course; do not

attempt!)

1 2 45 46 63Rank

Totally-ordered list of unique keysTotally-ordered

list of unique keys

Page 3: A Handy Data Structure

3

Finger SearchFinger SearchFinger SearchFinger Search

FingerSearch(f, x):Starting from f, search for x, then move f to final destination.

1 2 45 46 63Rank

O(log d) time if finger rank changes by d

What Destination?What Destination?

Page 4: A Handy Data Structure

4

Finger SearchFinger SearchFinger SearchFinger Search

1 2 45 46 63Rank

O(log d) time if finger rank changes by d

Straightforward for sorted arrays…

Page 5: A Handy Data Structure

5

Balanced Search TreesBalanced Search TreesBalanced Search TreesBalanced Search Trees

BSTs can be seen as versatile sorted arraysCan we do finger search on BSTs?

8

1 153 1311975

2 14106

4 12

Page 6: A Handy Data Structure

6

Brown and Tarjan, 1979Brown and Tarjan, 1979Brown and Tarjan, 1979Brown and Tarjan, 1979

Level-linked 2-3 TreesWorst case bound5 pointers / key

8

1 153 1311975

2 14106

4 12

Page 7: A Handy Data Structure

7

Tarjan and Van Wyk, 1988Tarjan and Van Wyk, 1988Tarjan and Van Wyk, 1988Tarjan and Van Wyk, 1988

Heterogeneous Finger Search TreesAmortized bound2 pointers / key

8

1 153 1311975

2 14106

4 12Inverted SpineInverted Spine

Page 8: A Handy Data Structure

8

This PaperThis PaperThis PaperThis Paper

How to achieve the best of both worlds? (sort of)Worst case boundAs few pointers as possible

Page 9: A Handy Data Structure

9

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

Page 10: A Handy Data Structure

10

Why Finger Search?Why Finger Search?Why Finger Search?Why Finger Search?

Finger search is theoretically appealingMerging of two sorted list of m and n keys takes

time, where m · nOptimal in comparison-based modelsEasy to extend to set intersection and union

Locality is RealityLocality is Reality

Page 11: A Handy Data Structure

11

In this paper…In this paper…In this paper…In this paper…

We introduce another way to support finger searchAssume 2 pointers per key (left, right)Worst-case O(log d) boundDuring runtime, maintain an O(log n)-size auxiliary data structure for an n-key degree-balanced BSTInsertions and deletions can be interleaved with finger searches in any order

Page 12: A Handy Data Structure

12

Space - Time Price ChartSpace - Time Price ChartSpace - Time Price ChartSpace - Time Price Chart

VersionTree Size

Time Bound Space

Level-link 2,3 [BT79]

n+5n = 6nWorst case O(log

d)O(1)

Hetero. RB [VT88]

n+2n = 3nAmortized O(log

d)O(1)

Skip List [P90] n+2n = 3n Expected O(log d) O(1)

Splay Tree [ST85,C95]

n+2n = 3nAmortized O(log

d)O(1)

Treaps [AS96] n+3n = 4n Expected O(log d) O(1)

Functional List [KT96]

n+~3n = ~4n

Worst case O(log d)

O(1)

Hetero. Treaps [BB]

n+2n = 3n Expected O(log d) O(1)

“This Paper” [BMW03]

n+2n = 3nWorst case O(log

d)O(log n)

Page 13: A Handy Data Structure

13

In the rest of this talk…In the rest of this talk…In the rest of this talk…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 treeFinger will only go forward

Page 14: A Handy Data Structure

14

Special Case: In-order WalkSpecial Case: In-order WalkSpecial Case: In-order WalkSpecial Case: In-order Walk

If finger search is possible, then in-order walk must be worst-case O(1) time per step.

8

1 153 1311975

2 14106

4 12

Page 15: A Handy Data Structure

15

In-order WalkIn-order WalkIn-order WalkIn-order Walk

Need to walk up, e.g., at 5

8

1 153 1311975

2 14106

4 12

Page 16: A Handy Data Structure

16

In-order WalkIn-order WalkIn-order WalkIn-order Walk

Need to walk up, e.g., at 5Classic: use a “Right Parent Stack”

8

1 153 1311975

2 14106

4 12

5

6

8

Rps

Page 17: A Handy Data Structure

17

In-order WalkIn-order WalkIn-order WalkIn-order Walk

8

1 153 1311975

2 14106

4 12

Need to walk down, e.g., at 8

Page 18: A Handy Data Structure

18

In-order WalkIn-order WalkIn-order WalkIn-order Walk

8

1 153 1311975

2 14106

4 12

Need to walk down, e.g., at 8Can’t start chasing pointers after

we’ve arrived at 8.Be Eager…Be Eager…

Page 19: A Handy Data Structure

19

In-order WalkIn-order WalkIn-order WalkIn-order Walk

Chase them beforehand, one at a time!

When we arrive at 8, 9 has already been “discovered”.8

1 153 1311975

2 14106

4 12

leaving 4

leaving 6

leaving 7

Page 20: A Handy Data Structure

20

The HandThe HandThe HandThe Hand

Each node on the Rps maintainsa prefix of its right-left spine.(How long?)

5

6

8

Rps

node

x1

x3

x2

s1

s3

s2

spine

8

1 153 1311975

2 14106

4 12

12

Page 21: A Handy Data Structure

21

In-order WalkIn-order WalkIn-order WalkIn-order Walk

1. Pop top cell and keep its spine s2. Extend spine of new top cell3. Prepend s to Rps

5

6

8

Rps

node

x1

x3

x2

s1

s3

s2

spine

8

1 153 1311975

2 14106

4 12

12

Page 22: A Handy Data Structure

22

55665566

1. Pop top cell and keep its spine s

2. Extend spine of new top cell3. Prepend s to Rps

6

8

Rps

8

1 153 1311975

2 14106

4 12

12

Page 23: A Handy Data Structure

23

55665566

1. Pop top cell and keep its spine s2. Extend spine of new top cell3. Prepend s to Rps

6

8

Rps

8

1 153 1311975

2 14106

4 12

712

Page 24: A Handy Data Structure

24

55665566

1. Pop top cell and keep its spine s2. Extend spine of new top cell3. Prepend s to Rps

6

8

Rps

7

8

1 153 1311975

2 14106

4 12

12

Page 25: A Handy Data Structure

25

At 6At 6At 6At 6

1. Pop top cell and keep its spine s2. Extend spine of new top cell3. Prepend s to Rps

6

8

Rps

7

8

1 153 1311975

2 14106

4 12

12

Page 26: A Handy Data Structure

26

66776677

1. Pop top cell and keep its spine s

2. Extend spine of new top cell3. Prepend s to Rps

8

Rps

7

8

1 153 1311975

2 14106

4 12

12

Page 27: A Handy Data Structure

27

66776677

1. Pop top cell and keep its spine s2. Extend spine of new top cell3. Prepend s to Rps

Rps

8

1 153 1311975

2 14106

4 12

7

8

10

12

Page 28: A Handy Data Structure

28

66776677

1. Pop top cell and keep its spine s2. Extend spine of new top cell3. Prepend s to Rps

7

8

Rps

8

1 153 1311975

2 14106

4 12

10

12

Page 29: A Handy Data Structure

29

At 7At 7At 7At 7

1. Pop top cell and keep its spine s2. Extend spine of new top cell3. Prepend s to Rps

7

8

Rps

8

1 153 1311975

2 14106

4 12

10

12

Page 30: A Handy Data Structure

30

Finger SearchFinger SearchFinger SearchFinger Search

During an in-order walk, we know the future.

But that’s not the case in finger search! 8

1 153 1311975

2 14106

4 12

Page 31: A Handy Data Structure

31

Surprise!Surprise!Surprise!Surprise!

Use the Hand!

curr

RP

peer

Rps

s’

scurr

RP

s

s’[atlas, peer)

Length of PrefixLength of Prefix

Page 32: A Handy Data Structure

32

Finger DestinationsFinger DestinationsFinger DestinationsFinger Destinations

curr

RP

peer

s

s’[atlas, peer)

Page 33: A Handy Data Structure

33

Extensions and Future WorkExtensions and Future WorkExtensions and Future WorkExtensions and Future Work

Refer to paper“Real” degree-balanced search treesGoing backwardInterleaving with insertions and deletions

Future WorkExperiments (especially on database prefetching)

Page 34: A Handy Data Structure

34

Q & AQ & AQ & AQ & A

Thank you for your attention.