Deadline: Saturday 18 April, 2020: Data Strucctures Assignment 2
Deadline: Saturday 18 April, 2020: Data Strucctures Assignment 2
Assignment 2
1 4
2 6
5 9
Deleting root 7
1
4
1 6
2 5 9
Result = 3, 4, 5
5 6
2 3
1 6 1 9
2 9 2 7
7
7 9 2
4 5 6 7
1 9 1 1
1
2 2
Result = 3, 4, 5, 6, 7, 9, 2, 1.
b) Show the result of inserting 2, 1, 4, 5, 9, 3, 6, and 7 into an initially empty AVL tree.
-2 -1
2 2
-2
0 -2 0 0 2
1 5 1 1
1 4
-1 0 0 1 5
left rotate
5 4 9 Right, Left 1 0
4 9
0 0
-2 9
2 -1 3
4
1 1
0
1 4 -2
2 5
1 0
5 0 0 1 Right, Left
9
1
3 9
0
3 -1 0
6
4
0 -1
2 6
0 0 0 1
1 3 9
5
0
7
c) Compare AVL tree to binary search tree. Which is faster? How much faster?
Answer:
2) For a n node binary search tree max level 2) AVL Tree number of levels is always log
could be n and min log (n) (n).
3) In worst case the cost Binary Search Tree 3) The cost of AVL tree is O (nlogn) in all
is O(n^2) and O(n log n) in Best Case cases (best case, average case and worst case).