AVL Trees Two - Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

Some concept of Data Structures are Abstract, Balance Factor, Complete Binary Tree, Dynamically, Storage, Implementation, Sequential Search, Advanced Data Structures, Graph Coloring Two, Insertion Sort. Main points of this lecture are: Avl Trees Two, Avl Node Structure, Binary Search Tree, Balance Factor, Data, Insert, Ready, Algorithms, Retrieval Algorithms, Binary Tree

Typology: Slides

2012/2013

Uploaded on 04/30/2013

dinpal
dinpal 🇮🇳

3.6

(12)

73 documents

1 / 21

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
AVL Trees
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download AVL Trees Two - Data Structures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

AVL Trees

AVL Insert

 Now that we have seen how to balance a tree, we are ready to look at the algorithms.  The search and retrieval algorithms are the same as for any binary tree.  However, because the AVL tree is a special case of a binary search tree, you will want to use an inorder traversal method. Docsity.com

AVL Insert

 As with the BST, all inserts take place at a leaf (or leaf-like) node.  To find the appropriate leaf node, we follow the path from the root, going left when the new data node’s key is less than the root node’s key and right when it’s greater.  Once we have found the leaf, we connect the new node to the leaf and begin to back out of the tree.

AVL Delete

 The delete logic is similar to the BST delete logic.  Again, however, we must make sure that we include the logic to keep the tree balanced.

Counting nodes

Height 0 1 2 3 4 5 6 7 8 9 10 Num Nodes 1 2 4 7 12 20 33 54 88 143 232

Relationship to Fibonacci

 Let N be the fewest number of nodes in an AVL tree of height H  It is straightforward to show that N = F(H+3) - 1 , where F(k) is the k th^ Fibonacci number  For large values of k ,

F ( k ) l

1 5

1 + 5 2

k

Solving for H

 if we solve this near equality for H, we

get

H  1.44 log 2 N

 This means that the height of an AVL

tree with N nodes is no more than 44%

larger than the optimal height of a

binary search tree with N nodes