You are on page 1of 15

Splay Tree ADT

m.burce deptofcompe
Splay Tree
• a self-adjusting form of binary search tree
• does not maintain tree to be balanced
• tree restructuring is called splaying
• splaying occurs whenever the tree is accessed
– insert, delete, search
• splaying involves moving a specified node to
the root of the tree after each insert, delete,
search
m.burce deptofcompe
When to Splay
• Search:
– Successful: Splay node where key was found.
– Unsuccessful: Splay last-visited internal node (i.e.,
last node with a key).
• Insert:
– Splay newly added node.
• Delete:
– Splay parent of removed node (which is either the
node with the deleted key or its successor).
m.burce deptofcompe
Splaying sub-operations
• done by performing a sequence of rotations along
the path from the node to the root

Zig: terminating single rotations

Zig-zig: two single rotations

Zig-zag: double rotation

m.burce deptofcompe
Zig

NOTE: rotation is symmetric

m.burce deptofcompe
zig-zig

NOTE: rotation is symmetric

m.burce deptofcompe
zig-zag

m.burce deptofcompe
Complete Example
44

Splay(78) 50

17 88

32 65 97
zig-zag
28 54 82

z
29 76
y
80

x 78

m.burce deptofcompe
Complete Example
44

Splay(78) 50

17 88

32 65 97
zig-zag
28 54 82

x
29 78

z 76 80 y

m.burce deptofcompe
Complete Example
44

Splay(78) 50

17 88

32 z 65 97
zig-zag
y
28 54 82

29 78 x

76 80

m.burce deptofcompe
Complete Example
44

Splay(78) 50

17 88

32 x 78 97
zig-zag
28 z 65 y 82

29 54 76 80

m.burce deptofcompe
Complete Example
44
z
Splay(78) 50

17 88 y

32 x 78 97
zig-zag
28 65 82

29 54 76 80

m.burce deptofcompe
Complete Example
44
x
78
Splay(78)
17 50 z 88 y

82
32 97
65
zig-zag
80
28
54 76

29

m.burce deptofcompe
Complete Example
y 44
x
78
Splay(78)
17 50 88 w

82
32 97
65
zig
80
28
54 76

29

m.burce deptofcompe
Complete Example
78 x
y 44

Splay(78)
17 50 88 w

82
32 97
65
zig
80
28
54 76

29

m.burce deptofcompe

You might also like