231 ICS202 Assignment 3 V03
231 ICS202 Assignment 3 V03
us
Answer: TCM th
Ten
O nel
Answer:
Ten 2TCEItn
th
expand 2 2T 4 4
2n
22127C It
2312T Ya 4 3m
Tin 2102
I
2 TL
7tnl09z K
in
109am n
Nt 101N
Page 1 of 5
I O noon
Question II. (50 points) (Trees)
1. (20 points) Construct the AVL tree by inserting the following keys into an empty tree, in order.
31, 36, 42, 18, 15, 24, 38, 28,25
RRRontation IL Rot
36121 36 i
3112
36 Col
131221 42 o
42 o
18107
36 Ell
31107 42 o 18111 6115
I 3110
15101
42901
38 RL
R Rot
insert
insert 241
3612 3110
31107 31 l 1801
42107 1 24101138
1811 4801 l 1,801
G 15 1510 2410
3g 1510 24cal
36,22 36101
92C
31
y go 42117
I
24601 38
28 c nsort
inert 25 AL
31111 31
31111
1847 11
18117 38101 380
8
15,24cal 1 2
3
15,1 8 0
2410,36101
0
gza 420
926 2510
Page 2 of 5
2. (10 points) Consider the following BST:
OS
replace 35
µ by the smallest
right subtree
b. (5 points) Delete key 46 by Merging ( from the original tree, i.e. Key 35 is there)
O
g
Iot ad
small's Page 3 of 5
Question III. (20 points) (Trees)
Write a method that prints all the proper ancestors of a given key in a given binary tree. For example if the key is
55, and the tree is the one given in QII.2, the method should print 60, 35, 46
You may use the method
Page 4 of 5
Question IV. (20 points) (Binary Heaps)
Sort the following array using heap sort algorithm. [120, 110, 310, 30, 50, 70, 90]
maxhoan
building a
310
310,110 12030,50170190
110 120
30 go
to Igo
and replace root by last inserted node
root
potatodoverenso the the heap by y
1 and size
110
1200
I I
30 70
So
90,110 12030,501701310
Submission Guidelines will be announced later.
Page 5 of 5
percolate up
now
120
I
110 96
I
3 70
50 120
111019030,501707310
repento steps
I
go
3 5011203107
u 70110,901
up
percolate
110
I
70 Do
I
30 150 1129310
110170,9013950
repent story
59
To
90,301119129310
3 50,70
percolate up
199
170 50
30
90,701501301119129310
repeat stops
30,50170199119120310
go
percolate up
70
70,50130190119120310
36
50
repanto 36001 Max heap
Already
50 no wood for percolate
70199119129310
50,30
36
re Ponte stop 1
30150,701901191203107
30
size 131 the
the hoop
Since in Ascending
will be sorted
array now order