1 A Handy Data Structure Space-Efficient Finger Search on Degree-Balanced Search Trees Guy Blelloch,...

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
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    216
  • download

    0

Transcript of 1 A Handy Data Structure Space-Efficient Finger Search on Degree-Balanced Search Trees Guy Blelloch,...

1

A Handy Data StructureA Handy Data Structure

Space-Efficient Finger Search on

Degree-Balanced Search Trees

Guy Blelloch, Bruce Maggs, Maverick Woo

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

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?

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…

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

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

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

8

This PaperThis PaperThis PaperThis Paper

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

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.

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

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

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)

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

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

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

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

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

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…

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

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

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

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

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

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

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

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

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

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

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

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

31

Surprise!Surprise!Surprise!Surprise!

Use the Hand!

curr

RP

peer

Rps

s’

scurr

RP

s

s’[atlas, peer)

Length of PrefixLength of Prefix

32

Finger DestinationsFinger DestinationsFinger DestinationsFinger Destinations

curr

RP

peer

s

s’[atlas, peer)

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)

34

Q & AQ & AQ & AQ & A

Thank you for your attention.