+ All Categories
Home > Documents > Splay Tree

Splay Tree

Date post: 23-Nov-2014
Category:
Upload: anon506472
View: 235 times
Download: 0 times
Share this document with a friend
Description:
Splay Tree
Popular Tags:
33
SPLAY TREE Castaneda, Jonathan S. Piscos, Shiela Mae
Transcript
Page 1: Splay Tree

SPLAY TREECastaneda, Jonathan S.

Piscos, Shiela Mae

Page 2: Splay Tree

INTRODUCTION

Was invented by Daniel Dominic Sleator and Robert Endre Tarjan in1985.

All normal operations on a binary search tree are combined with one basic operation called splaying.

It performs basic operations such as insertion, look-up and removal in O(log n) amortized time.

Page 3: Splay Tree

ADVANTAGES

Simple implementation Comparable Performance Small memory footprint Possibility of creating a persistent data

structure Working well with nodes containing identical

keys

Page 4: Splay Tree

DISADVANTAGES

Perhaps the most significant disadvantage of splay trees is that the height of a splay tree can be linear

Page 5: Splay Tree

OPERATIONSSplayingInsertionDeletion

Page 6: Splay Tree

SPLAYING

When a node x is accessed, a splay operation is performed on x to move it to the root.

To perform a splay operation we carry out a sequence of splay steps, each of which moves x closer to the root.

The three types of splay steps are: Zig Step Zig-zig Step Zig-zag Step

Page 7: Splay Tree

ZIG STEP

This step is done when p is the root. The tree is rotated on the edge between x and p. Zig steps exist to deal with the parity issue and will be done only as the last step in a splay operation and only when x has odd depth at the beginning of the operation.

Page 8: Splay Tree

ZIG STEP>1P

X

A B

C

Page 9: Splay Tree

ZIG STEP>1-2

P

X

A B

C

Right Child will be transferred

Page 10: Splay Tree

ZIG STEP>1-2-3

P

X

A

B C

Page 11: Splay Tree

ZIG-ZIG STEP

This step is done when p is not the root and x and p are either both right children or are both left children. The picture below shows the case where x and p are both left children. The tree is rotated on the edge joining p with its parent g, then rotated on the edge joining x with p. Note that zig-zig steps are the only thing that differentiate splay trees from the rotate to root method introduced by Allen and Munro prior to the introduction of splay trees.

Page 12: Splay Tree

ZIG-ZIG STEP>1

X

P

G

A B

C

D

Page 13: Splay Tree

ZIG-ZIG STEP>1-2

X

P

G

A B

CD

Page 14: Splay Tree

ZIG-ZIG STEP>1-2-3

X

P

G

A B

C D

Page 15: Splay Tree

ZIG-ZIG STEP>1-2-3-4X

P

G

A B C D

Page 16: Splay Tree

ZIG-ZIG STEP>1-2-3-4-5X

P

G

A

B

C D

Page 17: Splay Tree

ZIG-ZAG STEP

This step is done when p is not the root and x is a right child and p is a left child or vice versa. The tree is rotated on the edge between x and p, then rotated on the edge between x and its new parent g.

Page 18: Splay Tree

ZIG-ZAG STEP>1G

P

X

D

CB

A

Page 19: Splay Tree

ZIG-ZAG STEP>1-2G

P

X

D

CB

A

Page 20: Splay Tree

ZIG-ZAG STEP>1-2-3G

P

X

D

B

C

A

Page 21: Splay Tree

ZIG-ZAG STEP>1-2-3-4

G

X

D

C

BA

P

Page 22: Splay Tree

ZIG-ZAG STEP>1-2-3-4-5X

DCBA

GP

Menu

Page 23: Splay Tree

INSERTION

Start with an empty splay tree and insert pairs with keys 1, 2, 3, …, in this order.

1 1

2 1

2

Page 24: Splay Tree

INSERTION

To insert a node x into a splay tree, we first insert it as with a normal binary search tree. Then we splay the new node x to the top of the tree

Page 25: Splay Tree

INSERTION

Start with an empty splay tree and insert pairs with keys 1, 2, 3, …, in this order.

1

2

3

1

2

3

Menu

Page 26: Splay Tree

DELETION

To delete a node x, we use the same method as with a binary search tree. If x has two children, we replace its value with either the rightmost node of its left sub tree (its in-order predecessor) or the leftmost node of its right subtree (its in-order successor). Then we remove that node. After deletion, we splay the parent of the removed node to the top of the tree.

Page 27: Splay Tree

DELETION

Delete 10

6 11

10

8

7

12

13

17

18

Parent

Page 28: Splay Tree

8

DELETION

Replace 10 with the leftmost node of its right sub tree

6 11

10

7

12

13

8

17

18

Move 7 up

Page 29: Splay Tree

DELETION

Splay the parent

6 11

8

7

12

13

17

18

Page 30: Splay Tree

DELETION

11

6

7

8

13

12

17

18

Transfer 13

Page 31: Splay Tree

DELETION

11

6

7

8

13

12

17

18

Page 32: Splay Tree

DELETION

116

7

8

13

12

17

18

Page 33: Splay Tree

END OF REPORT

Thank you for listeningand

Hope we can all graduate this SY-2011..ahaha


Recommended