lec8 - Outline • BST: insertion, deletion, search • AVL...

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: Outline • BST: insertion, deletion, search • AVL tree: definition • AVL tree: insert • AVL tree: delete • AVL tree maintenance: rotations Lecture 8, AVL Tree p. 1 Basic Operations on BST Find: • Compare to the value at root • If not at the root, recursively find in the appropriate subtree • Stop when an empty tree is reached Insert: • Search until the empty subtree is reached • Replace the empty subtree with a node containing the value Delete: • Search the value • If the value is at a leaf, delete the leaf • If the value is at a node with one child, delete the node, and promote its child • If the value is at a node with two children, move the value in the predecessor (or successor) into this node, delete its predecessor (or successor) Lecture 8, AVL Tree p. 2 Rotations: Single Rotation x y y Tc right−rotate(x) Ta x Ta Tb left−rotate(y) Tb Tc Lecture 8, AVL Tree p. 3 Rotations: Double Rotation 2 x z 1 y z Tc y x Ta Tb1 Tb2 1: left−rotate(y) 2: right−rotate(x) Ta Tb1 Tb2 Tc Lecture 8, AVL Tree p. 4 An Example 7 3 8 2 5 9 0 Insert(1) Delete(8) 4 6 Lecture 8, AVL Tree p. 5 ...
View Full Document

This note was uploaded on 07/17/2010 for the course CS 240 taught by Professor Ortiz during the Spring '09 term at Waterloo.

Page1 / 5

lec8 - Outline • BST: insertion, deletion, search • AVL...

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