AVL tree assignment - Data Structure and algorithms, Assignments of Data Structures and Algorithms

AVL tree assignment - basic introduction and recommended for beginners

Typology: Assignments

2018/2019

Uploaded on 08/28/2021

unknown user
unknown user ๐Ÿ‡ฑ๐Ÿ‡ฐ

1 document

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 201 Data Structures โ€“ AVL tree Tutorial
1) For binary search tree balancing is not necessary. But for AVL tree balancing is necessary.
2)
a) Height of the left sub tree of the node v and height of the right sub tree of the node v
differ at most 1. That differenceshould be exactly -1,0,1. Balance of the node v can
calculate from fellow equation,
balance = height of left sub tree of node v โ€“ height of right sub tree of node v
Balance for node a = height of left sub tree โ€“ height of right sub tree
= 2 โ€“ 2
= 0
Balance for node b = height of left sub tree โ€“ height of right sub tree
= 1 โ€“ 0
= 1
Balance for node c = height of left sub tree โ€“ height of right sub tree
= 0 โ€“ 1
= -1
pf3
pf4
pf5

Partial preview of the text

Download AVL tree assignment - Data Structure and algorithms and more Assignments Data Structures and Algorithms in PDF only on Docsity!

CS 201 Data Structures โ€“ AVL tree Tutorial

1) For binary search tree balancing is not necessary. But for AVL tree balancing is necessary.

a) Height of the left sub tree of the node v and height of the right sub tree of the node v

differ at most 1. That difference should be exactly -1,0,1. Balance of the node v can calculate from fellow equation, balance = height of left sub tree of node v โ€“ height of right sub tree of node v Balance for node a = height of left sub tree โ€“ height of right sub tree = 2 โ€“ 2 = 0 Balance for node b = height of left sub tree โ€“ height of right sub tree = 1 โ€“ 0 = 1 Balance for node c = height of left sub tree โ€“ height of right sub tree = 0 โ€“ 1 = -

Balance for node d = height of left sub tree โ€“ height of right sub tree = 0 โ€“ 0 = 0 Balance for node e = height of left sub tree โ€“ height of right sub tree = 0 โ€“ 0 = 0

b) Insertion, deletion and searching operations of AVL tree take O(log n) in both the

average and worst cases.

a) When inserting a new node to AVL tree if AVL tree become unbalanced, rotations are

used for rebalance it.

b) RR rotation โ€“ Right-Right rotation

LL rotation โ€“ Left-Left rotation RL rotation โ€“ Right-Left rotation LR rotation โ€“ Left- Right rotation

c) Single rotation - RR rotation, LL rotation

Double rotation - RL rotation, LR rotation

Worst case scenarios of runtime of Part a) BST Part b) AVL tree Insertion O(1) O(log n) Deletion O(n) Search O(n)

c)

a) P.T.O