L17_SplayTree

L17_SplayTree - but also has the effect of roughly halving...

Info iconThis preview shows pages 1–18. Sign up to view the full content.

View Full Document Right Arrow Icon
Splay Tree Consider the following binary search tree 6 5 2 1 3 4 7 Page 1 of 18
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Splay Tree If node 1 is accessed, we want to push it to the root. 7 1 2 3 4 5 6 Hopefully, the tree becomes more balanced in the process of pushing. 1 Page 2 of 18
Background image of page 2
There are three cases of ‘pushing after access.’ Page 3 of 18
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Case 0: Zig A C B P A C B P This is exactly a single rotation. Page 4 of 18
Background image of page 4
Case 1: Zig-zag P A B G C D P A G D C B This is exactly a double rotation. Page 5 of 18
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Case 2: Zig-zig P D B A G C P A G D C B Page 6 of 18
Background image of page 6
P B D G P D B G A C P B P B C A P A B C D G P A B G C D P B D G P D B ZIG-ZIG ZIG-ZIG ZIG-ZAG ZIG-ZAG A P B D C G P A G D C B A C P B ZIG ZIG A C B P G Page 7 of 18
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Splaying at Node 1 P P D B G G D B 7 7 6 5 4 2 5 7 6 4 2 3 3 2 3 4 5 6 Page 8 of 18
Background image of page 8
Splaying at Node 1 P D G B P G D B 7 6 4 5 2 3 5 4 2 3 7 6 Page 9 of 18
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
5 4 2 3 7 6 2 3 4 5 6 7 Splaying not only moves the accessed node to the root,
Background image of page 10
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 12
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 14
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 16
Background image of page 17

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 18
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: but also has the effect of roughly halving the depth of the most nodes on the access path. Page 10 of 18 Splaying at Node 2 A C B P B P C A P D G B P G D B 7 6 1 4 3 5 5 4 3 7 6 1 7 1 6 4 3 5 Page 11 of 18 7 6 2 1 4 3 5 2 3 4 5 6 7 5 4 3 7 6 1 When access paths are long, the rotations tend to be good for future operations. Page 12 of 18 D C G B A P P G D C B A Splaying at Node 3 7 6 2 1 4 5 7 6 2 1 4 5 Page 13 of 18 A C B P B P C A Splaying at Node 4 6 2 3 1 6 5 2 1 3 5 Page 14 of 18 Splaying at Node 5 D C G B A P P G D C B A 2 3 1 4 6 6 2 3 1 4 Page 15 of 18 Splaying at Node 6 A C B P B P C A 2 3 1 4 5 6 2 3 1 4 5 Page 16 of 18 2 3 1 4 6 2 3 1 4 5 5 6 2 3 1 4 When accesses are cheap, the rotations are not as good and can be bad. Page 17 of 18 The analysis of splay tree is difficult, but splay trees are much simpler to program than AVL trees. Page 18 of 18...
View Full Document

{[ snackBarMessage ]}

Page1 / 18

L17_SplayTree - but also has the effect of roughly halving...

This preview shows document pages 1 - 18. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online