in DS retagged by
347 views
3 votes
3 votes
Let $\mathrm{T}$ be the smallest AVL tree of height $h$. How many nodes does it have, if the smallest AVL tree of height $h-2$ has $m$ nodes and the smallest AVL tree of height $h-3$ has $k$ nodes?
  1. $m+k+2$
  2. $m+2 k$
  3. $2 m+k$
  4. $2 m+k+2$
in DS retagged by
347 views

1 comment

$ \large{\colorbox{yellow}{Detailed video solution of this question with direct time stamp}}$

All India Mock Test 4 - Solutions Part 1

0
0

1 Answer

0 votes
0 votes
Given , N(h-2) = m

                        N(h-3) = k ;

The formula for AVL Tree Height is given as :

                             N(h) = N(h-1) + N(h-2) + 1      // N: # Node

Now , N(h-1) = N(h-2) + N(h-3) +1  // substitute in above equation,

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

                          N(h) = 2*N(h-2) + N(h-3) + 2

                          N(h) = 2m+k+2

1 comment

@thecoderyabham, here the question is asking for smallest AVL tree of height h with given number of nodes. For smallest AVL tree, we need to stuff maximum number of nodes in each level. So shouldn’t the recurrence relation go like this:
N(h) = 1 + 2*N(h-1) ?
Correct me if I’m wrong.

0
0
Answer:

Related questions