{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lec27a - Lecture 27 Balanced Binary Search Trees Ch 16.1...

This preview shows pages 1–12. Sign up to view the full content.

Lecture 27 Balanced Binary Search Trees Ch. 16.1, 17.1-3

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

View Full Document
Balanced Binary Search Trees height is O(log n) , where n is the number of elements in the tree AVL (Adelson-Velsky and Landis) trees red-black trees get, put, and remove take O(log n) time
Balanced Binary Search Trees Indexed AVL trees Indexed red-black trees Indexed operations also take O(log n) time

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

View Full Document
Balanced Search Trees weight balanced binary search trees 2-3 & 2-3-4 trees AA trees B-trees BBST etc.
AVL Tree binary tree for every node x , define its balance factor balance factor of x = height of left subtree of x - height of right subtree of x balance factor of every node x is -1 , 0 , or 1

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

View Full Document
Balance Factors 0 0 0 0 1 0 -1 0 1 0 -1 1 -1 This is an AVL tree.
Height The height of an AVL tree that has n nodes is at most 1.44 log 2 (n+2) . The height of every n node binary tree is at least log 2 (n+1) .

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

View Full Document
AVL Search Tree 0 0 0 0 1 0 -1 0 1 0 -1 1 -1 10 7 8 3 1 5 30 40 20 25 35 45 60
put(9) 0 0 0 0 1 0 -1 0 1 0 -1 1 -1 9 0 -1 0 10 7 8 3 1 5 30 40 20 25 35 45 60

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

View Full Document
put(29) 0 0 0 0 1 0 0 1 0 -1 1 -1 10 7 8 3 1 5 30 40 20 25 35 45 60 29 0 -1 -1 -2 RR imbalance => new node is in right subtree of right subtree of blue node (node with bf = -2 )
put(29) 0 0 0 0 1 0 0 1 0 -1 1 -1 10 7 8 3 1 5 30 40 25 35 45 60 0 RR rotation.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}