L14_BinarySearchTree

L14_BinarySearchTree - Binary Search Tree 0123849...

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

View Full Document Right Arrow Icon
Binary Search Tree 0170980 Bob/UC/SEG Will/CC/CSC 0160039 May/NA/IEG 0150957 John/NA/CSC 0123849 This is an ex- ample of bad binary search trees. Page 1 of 46
Background image of page 1

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

View Full DocumentRight Arrow Icon
Balanced Binary Search Tree Trees created by consecutive insertNode messages are in general unbalanced. 0170980 Bob/UC/SEG Will/CC/CSC 0160039 May/NA/IEG 0150957 John/NA/CSC 0123849 t = new EmptyBinaryTree(); t = t.insertNode( ); John/NA/CSC 0123849 t = t.insertNode( ); May/NA/IEG 0150957 t = t.insertNode( ); Will/CC/CSC 0160039 t = t.insertNode( ); 0170980 Bob/UC/SEG Page 2 of 46
Background image of page 2
Balanced Binary Search Tree A tree is balanced if, at each node, the heights of the left and right subtrees differ by at most one. Page 3 of 46
Background image of page 3

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

View Full DocumentRight Arrow Icon
Are the following Balanced Binary Search Trees? Page 4 of 46
Background image of page 4
Is the following a Balanced Binary Search Tree? Page 5 of 46
Background image of page 5

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

View Full DocumentRight Arrow Icon
Is the following a Balanced Binary Search Tree? Page 6 of 46
Background image of page 6
Question: Are the following trees balanced? Page 7 of 46
Background image of page 7

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

View Full DocumentRight Arrow Icon
AVL Tree An AVL (Adelson-Velskii and Landis) tree is a binary search tree with a balance condition. An AVL tree is identical to a binary search tree, except that for every node in the tree, the height of the left and right subtrees can differ by at most 1. Page 8 of 46
Background image of page 8
Is the following an AVL Tree? Page 9 of 46
Background image of page 9

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

View Full DocumentRight Arrow Icon
Is the following an AVL Tree? Page 10 of 46
Background image of page 10
Question: Are the following AVL Trees? Page 11 of 46
Background image of page 11

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

View Full DocumentRight Arrow Icon
Binary Search Tree Balancing Strategy: Rotation Fried Eggs Sausages Fried Eggs Ham Ham ROTATION Sausages Fried Eggs Ham Fried Eggs Page 12 of 46
Background image of page 12
Rotation Observation A rotation is needed only when a new node is inserted into an AVL Tree. WHY?
Background image of page 13

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

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

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 46

L14_BinarySearchTree - Binary Search Tree 0123849...

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

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