1.

Prove that the number of nodes with degree 2 in any Binary tree is 1 less than the number of leaves. 

Answer»

The proof is by induction on the size n of T .

Let L(T) = No of leaves & D2(T)= No of nodes of T of degree 2

To Prove D2(T)=L(T)-1 

Basic Case : n=1 , then T consists of a single node which is a leaf . 

L(T)=1 and D2(T)=0

So D2(T)=L(T)-1 

Induction Step : Let n > 1 and assume for all non empty trees T1 of size k<n  that D2(T`)=L(T`)-1 

Since n >1 , at least one of x=left(T) or y=right(T) is non empty

Assume x is non empty ; the other case is symetric By the induction hypothesis , 

D2(x) = L(y)-1

IF y is empty , then again by the induction hypothesis ,

D2(y) =L(y)-1 and

D2(T) =D2(x)+D2(y)+1

=L(x)-1+L(y)-1+1

= L(x)+L(y)-1 

D2(T) = L(T)-1 Hence Proved



Discussion

No Comment Found

Related InterviewSolutions