This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: ZigZig
Performed when the node x forms a linear chain with its
parent and grandparent.
i.e., rightright or leftleft
x z
y y
T4 x
T3
T1 T1
T2 T2 CSE 2011
Prof. J. Elder z zigzig T3  46  T4 Last Updated: 3/3/10 6:14 PM ZigZag
Performed when the node x forms a nonlinear chain
with its parent and grandparent
i.e., rightleft or leftright
z x
y z zigzag y x T1 T4
T2 T1 T2 T3 T4 T3 CSE 2011
Prof. J. Elder  47  Last Updated: 3/3/10 6:14 PM Zig
Performed when the node x has no grandparent
i.e., its parent is the root y x zig x w y T4
w
T3
T1 T1 T2 T3 T4 T2 CSE 2011
Prof. J. Elder  48  Last Updated: 3/3/10 6:14 PM Splay Trees & Ordered Dictionaries
which nodes are splayed after each operation?
method
find(k) insert(k,v) remove(k) CSE 2011
Prof. J. Elder splay node
if key found, use that node
if key not found, use parent of external node where search
terminated
use the new node containing the entry inserted
use the parent of the internal node that was actually
removed from the tree (the parent of the node that the
removed item was swapped with)  49  Last Updated: 3/3/10 6:14 PM Recall BST Deletion
Now consider the case where the key k to be removed is stored at a
node v whose children are both internal
we find the internal node w that follows v in an inorder traversal
we copy key(w) into node v
we remove node w and its left child z (which must be a leaf) by means of
operation removeExternal(z) Example: remove 3 – which node will be splayed?
1 1 v v 3 5 2 8
6 w 2
9 8
6 9 5 z
CSE 2011
Prof. J. Elder  50  Last Updated: 3/3/10 6:14 PM ...
View
Full
Document
This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.
 Fall '11
 Elder
 Data Structures

Click to edit the document details