2. Introduction
• Searching on dynamic tables
– Insert/delete symbols from the set
– Using a binary search to maintain
• Eg. JAN, Feb, …
# comp. to find “NOV” = 6
Avg. # comp. = 42/12 = 3.5
Entering in a different order…
3. Enter months to Generate Balanced tree
• A balanced tree: JUL, FEB, MAY, …
• Any path from root-to-leaf is of the same
length (balanced) // vs. the skewed tree
– Max. # of id. Comparisons = 4, avg.=37/12
4. Form a Tree (degenerate to a chain)
• Lexicographic order
Max. # = 12
Avg. = 6.5
5. Objective
• Minimize (Max. & avg. search) time if the
binary tree is complete at all time
• To maintain that by re-structuring will
cause some insertions time-consuming
• It is possible to maintain a balanced tree!
• Avg. / worst case retrieval time O(log n)
• Adelson-Velskii-Landis binary
– Balanced with respect to heights of sub-trees
• O(log n): insert/delete/retrieve
6. Definition
• Height-balanced tree
– (1) Empty tree is height-balanced
– (2) non-empty binary tree T, left-subtree TL,
right-subtree TR:
T is height-balanced if
(i) TR and TL are height-balanced
(ii) |hL – hR| ≤ 1 where hL and hR are the heights of TR and
TL
• Balance factor
– BF(T) = hL – hR
– BF(T) = -1, 0, or 1for any node in an AVL tree
7. Construct AVL Tree
• Insert order: MAR, MAY, NOV, …
• Monitor BF(*), Rotate if necessary
– (1) RR
– (2) LL
– (3) LR
– (4) RL