261 views
0 votes
0 votes

I have a doubt in this question :

https://gateoverflow.in/3811/gate2005-it_50

I am posting this, as there is a very low probability my comment will be replied.

I wanted to progress in the solution by forming the recurrence . This was my logic :

T(h) : No. of nodes at height h

T(l,h-1) : No. of nodes in the left subtree having height h-1

T(r,h-1) : No. of nodes in the right subtree having height h-1

T(h) = T(l,h-1)+T(r,h-1)+1

Min. no. of nodes occur when diff between T(l,h-1) and T(r,h-1) is 2.

Recurrence :

T(h) = T(r,h-1)+2+T(r,h-1)+1

T(h)=2T(h-1) + 3

This is not correct, as T(1) should be 2. It gives 5; T(0)=1

Can anynody help me with correct recurrence?

1 Answer

Best answer
1 votes
1 votes
- You almost got that..

Min. no. of nodes occur when diff between T(l,h-1) and T(r,h-1) is 2.

- Yes, correct till this.

Recurrence :

T(h) = T(r,h-1)+2+T(r,h-1)+1

- Here, you are replacing T(l,h-1) with T(r,h-1) + 2. That means you are adding 2 more nodes to left subtree.

Why add 2 more nodes? We need min number of nodes, so just subtract 2 nodes.. i.e

Recurrence :

T(h) = T(r,h-1)-2+T(r,h-1)+1

T(h)=2T(h-1) - 1;

T(1)=2 This should be considered as base condition as h>0
selected by

Related questions

0 votes
0 votes
1 answer
1
Saurav asked Aug 31, 2015
969 views
The number of leaf nodes in the recurrence tree of the recurenceT(n) = T(n/4) + T(n/2) + n^2
1 votes
1 votes
1 answer
2
sripo asked Nov 14, 2018
1,570 views
T(n)=T(n/2)+2; T(1)=1when n is power of 2 the correct expression for T(n) is:a) 2(logn+1)b) 2lognc)logn+1d)2logn+1
0 votes
0 votes
1 answer
4
lucasbbs asked Feb 28, 2022
6,573 views
How do I apply the master theorem in the above recurrence? Please give details about which case and on hiow to solve the asymptotic analysis...