Document not found! Please try again

Self-Adjusting Data Structures - Department of Computer Science

48 downloads 710 Views 1MB Size Report
[C Okasaki Alternatives to Two Classic Data Structures Symposium on Computer Science Education 162-. 2. [C. Okasaki, Alternatives to Two Classic Data ...
Self‐Adjusting Data Structures

1

movve‐to‐frontt

Self‐Adjusting Data Structures 2

7

4

1

9

5

3

Search(2), Search(2), Search(2) , Search(5), Search(5), Search(5)

5

2

7

4

1

9

3

Lists th Annual ACM Symposium on  [[D.D. Sleator, R.E. Tarjan, Amortized Efficiency of List Update Rules, Proc. 16 , j , ff y f p , y p Theory of Computing, 488‐492, 1984] Dictionaries [D.D. Sleator, R.E. Tarjan, Self‐Adjusting Binary Search Trees, Journal of the ACM, 32(3): 652‐686, 1985] → splay trees splay trees Priority Queues [C.A. Crane, Linear lists and priority queues as balanced binary trees, PhD thesis, Stanford University, 1972] [D.E. Knuth. Searching and Sorting, volume 3 of The Art of Computer Programming, Addison‐Wesley, 1973] → leftist heaps l f h [D.D. Sleator, R.E. Tarjan, Self‐Adjusting Heaps, SIAM Journal of Computing, 15(1): 52‐69, 1986] → skew heaps [C. Okasaki, Alternatives to Two Classic Data Structures, Symposium on Computer Science Education, 162 [C Okasaki Alternatives to Two Classic Data Structures Symposium on Computer Science Education 162‐ 165, 2005] → maxiphobix heaps    Okasaki:  maxiphobix heaps are an alternative to leftist heaps ... but without the “magic”

2

3

Heaps (via Binary Heap‐Ordered Trees)

2 2

2

5

3 1

1

7

9

4

6

1

[C.A. Crane, Linear lists and priority queues as balanced binary  trees, PhD thesis, Stanford University, 1972] 3 [D.E. Knuth. Searching and Sorting, volume 3 of  2 The Art of Computer Programming, 3 Addison‐Wesley, 1973] 2

8

12 2

1

11

10

1

1

13

13

2

Each node distance to empty leaf Inv Distance right child  ≤ Inv. Distance right child ≤ left child left child ⇒ rightmost path ≤ ⎡log n+1⎤ nodes M i h bi Heaps Maxiphobic H Meld (               ,             )  x y T3 T1

T2

Meld                             Cut root + Meld

Leftist Heaps

2

=

1

=

MakeHeap FindMin Insert Meld DeleteMin MakeHeap, FindMin, Insert, Meld, DeleteMin

1

x  |Tp(v)|/2, otherwise light ⇒ any path ≤ log n light nodes

4 7

7 9

Potential  Φ = # heavy right children in tree

9 13

O(log n) amortized Meld Heavy right child on merge path before meld → replaced by light child ⇒ 1 potential released l l d for heavy node f h d ⇒ amortized cost 2∙ # light children on rightmost paths before meld

4

Skew Heaps – O(1) time Meld [D.D. Sleator, R.E. Tarjan, Self‐Adjusting Heaps, SIAM Journal of Computing, 15(1): 52‐69, 1986]

ƒ Meld = Bottom‐up merg of rightmost paths + swap all siblings on merge path 1 4 Meld (          13

5 8

1

1 ,                  )   =                            = 2 2

3 6 11

11

7 9

2 6

4 7

3

9

4 5 8

13

Φ = # heavy right children in tree + 2 ∙ # light children on minor & major path O(1) amortized Meld Heavy right child on merge path before meld → replaced by light child ⇒ 1 potential released Light nodes disappear from major paths (but might → heavy) ⇒ ≥ 1 potential released and 5 become a heavy  or a heavy or light right children light right children on major path major path ⇒ potential increase potential increase by ≤ by ≤ 4 4 and       become O(log n) amortized DeleteMin Cutting root ⇒ 2 new minor paths, i.e. ≤ 2∙log n new light children on minor & major paths

5

Splay Trees [D.D. Sleator, R.E. Tarjan, Self‐Adjusting Binary Search Trees, Journal of the ACM, 32(3): 652‐686, 1985]

ƒ Binary search tree with no balance information ƒ splay(x) = rotate x to root (zig/zag, zig‐zig/zag‐zag, zig‐zag/zag‐zig) root

y

x A

z

x

zig C

x

B

B

y D

A

x

y

A

D z

C

C

zig zag zig‐zag

z

y

y

A

x

zig‐zig i i

y

x

B

z

A

B

C

D

B

A

C

B

C

D

ƒ Search (splay), Insert (splay predecessor+new root), Delete (splay+cut root+join),  Join (splay max, link), Split (splay+unlink) v u F

z

zag‐zag zig‐zig i i

x

insert

y

x

u

E y

z

A

C

x B

A C

D

B

v

y

v

D

D E

z

F A

C B

u

E

F 6

Splay Trees [D.D. Sleator, R.E. Tarjan, Self‐Adjusting Binary Search Trees, Journal of the ACM, 32(3): 652‐686, 1985]

ƒ The access The access bounds of splay of splay trees are amortized (1) O(log n)  ( ) (2) Static optimall (3) Static finger optimal ((4) Working ) g set optimal (proof p (p requires q dynamic y change g of weight) g )

Σ

ƒ Static optimality:   Φ =       v log |Tv|

7

Suggest Documents