Download presentation
Presentation is loading. Please wait.
1
CS2420: Lecture 24 Vladimir Kulyukin Computer Science Department Utah State University
2
Outline Balanced Binary Trees (AVL Trees) –Section 4.4.
3
Definition: AVL Tree An empty binary tree is an AVL tree. If T is a non-empty binary tree, then T is an AVL tree if and only if: 1) Both sub-trees are AVL trees. 2) The heights of the sub-trees differ by at most 1 (AVL Tree Property). The height of an empty tree is defined to be -1, whereas the height of a tree with exactly one node is 0.
4
Balance Factors The balance factor (BF) of a node is the difference b/w the height of the node’s left sub-tree (HL) and the height of the node’s right sub-tree (HR). BF = HL – HR. By the AVL Tree Property, the balance factor of each node in an AVL tree must be -1, 0, or 1.
5
AVL Tree: Balance Factors 12 168 HL = 0HR = 0 HL = height of the left sub-tree. HR = height of the right sub-tree. BF = balance factor = HL – HR. BF = HL – HR = 0 – 0 = 0.
6
AVL Tree: Balance Factors (BFs) 12 8 HL = 0HR = -1 HL = height of the left sub-tree. HR = height of the right sub-tree. BF = balance factor = HL – HR. BF = HL – HR = 0 – (-1) = 1.
7
Example: AVL Tree with BFs 12 8 16 141510 256 BF = 0 BF = 1
8
Example: AVL Tree with BF’s 50 17 61 67 BF = 0 BF = -1 BF = 1 BF = 0
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.