Académique Documents
Professionnel Documents
Culture Documents
Que-8
(i):- Define the terms Internal Path Length and External
Path Length for a binary tree.
(ii):- Prove that for any binary tree of n internal nodes the
External Path Length: Internal Path Length + 2n;
Ans-8(i): Internal Path Length: - Internal Path Length of a
binary tree can be define as sum of Path Length of all the
internal nodes in the tree.
->A node with 1 or more child is called an Internal node.
Ans-8(ii): ->To prove that for any binary tree of n nodes External
Path Length: Internal Path Length + 2n;
->Lets take an Example:
Internal Nodes
B
External
Nodes
I=1+1+2+2+2+2
I=10.
n = total no of nodes.
E=10 + 2(7)
E=24.
So, we can say that for a binary tree External path
length=Internal path length + 2n.
Que-9
Construct AVL tree for the following set of month
March,May,August,April,January,December,July,February,J
une,October,September.
Ans-9:
1.March
0
March
2.May
-1
March
May
3.August
March
Aug
May
4.April
March
Aug
May
0
April
5.January
March
Aug
May
0
April
Jan
6.December
March
Aug
0
April
-1
May
Jan
L .R.
0
Dec
Jan
Aug
0
April
Dec
Now it is balance
Mar
-1
May
7.July
Jan
Aug
0
April
Mar
Dec
July
May
May
8.February
Jan
Aug
0
April
-1
Dec
Mar
-1
0
Feb
july
9.June
Jan
Aug
0
April
-1
Mar
Dec
-1
July
-1
May
May
-1
Feb
June
10.October
Jan
Aug
0
April
-1
Dec
Mar
-1
july
-1
0
Feb
0
June
0
Oct
11.September
Jan
Aug
balance
0
April
-1
-1
-1
Mar
It is not
Dec
-1
Feb
May
July
-1
-2
June
Oct
-1
Sept
Jan
Aug
L.L.
0
April
-1
Mar
It is balance
Dec
-1
0
Feb
Que-10
July
-1
0
June
Oct
0
May
0
Sept
12
-2
LL 12
0
15
18
-1
18
0
LL Rotation is to be performed when the right sub
tree of the node is having.
12
11 tree).
2. RR (Right Right) Rotation (having Left sub
For example: - 2
0
11
10
10
12
1
RR
0
0
RR Rotation is to be performed when the Left sub
tree of the node is having.
-1
10
LL
0
1
15
15
15
10
RR 0
10
20
-2 20
20
-2
0 22
-1
25
22
RR
0
22
20
25
LL
0
25
Exp : 12,6,9,11,10,4,7
1.)
12
12
2.)
6
12
0
12
3.)9
12
LR
-1
0
4.)11
9
-1
0 6
12 1
0 11
5.)10
9
-2
0 6
12 2
1 11
0
10
11
12
10
RL
0
1
6.)4
11
1 6
0
12
12
0 10
11
0
0 6
0 4
10
RR
7.)7
11
04
-1
1
12
1 10
1
0