Search Trees_Part_10

Search Trees_Part_10 - Zig-Zig Performed when the node x...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Zig-Zig Performed when the node x forms a linear chain with its parent and grandparent. i.e., right-right or left-left x z y y T4 x T3 T1 T1 T2 T2 CSE 2011 Prof. J. Elder z zig-zig T3 - 46 - T4 Last Updated: 3/3/10 6:14 PM Zig-Zag Performed when the node x forms a non-linear chain with its parent and grandparent i.e., right-left or left-right z x y z zig-zag 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.

Page1 / 5

Search Trees_Part_10 - Zig-Zig Performed when the node x...

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

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