AVL or BALANCED BINARY TREES - PowerPoint PPT Presentation

About This Presentation
Title:

AVL or BALANCED BINARY TREES

Description:

AVL or BALANCED BINARY TREES ... In a complete BST we have. Nodes in Tree Height of Tree. 2n 1 1 n. Hence: log(2n 1 1) n log(n) ... – PowerPoint PPT presentation

Number of Views:179
Avg rating:3.0/5.0
Slides: 8
Provided by: Bar38
Category:
Tags: avl | balanced | binary | trees | bst

less

Transcript and Presenter's Notes

Title: AVL or BALANCED BINARY TREES


1
AVL or BALANCED BINARY TREES
Definition An AVL Tree is a Binary Tree in which
for every node, the heights of its two subtrees
never differ by more than one
A BALANCE indicator is assigned to each node
2
Private members
Public base class members
New public subclass members
3
33
43
(0)
53
63
73
A Degenerate BST
An AVL Tree
4
(0)
Non-BST
Non AVL Tree
5
Time for Searching a Balanced Tree? In a complete
BST we have Nodes in Tree Height of Tree
2n1 1 n Hence
log(2n1 1) n log(n) Now the left hand
column stands for the size of the data set and
the right hand column for the time required to
search. Thus, n elements in a tree requires O(log
n) search time!
6
AVL Trees Insert and Maintain Balance
After an Insertion
Both LEFT HEAVY
(-2) Critical
subtree
Length of longest path to parent
K
Note INORDER on Both Before-After T1DT2KT3
(0)
(0)
Perform right rotation pivot is
K
Symmetric Case Both Trees RIGHT HEAVY
7
After Insertion
Left rotate with C as pivot
Right rotate with M as pivot
Another E.G. of Insert
Write a Comment
User Comments (0)
About PowerShow.com