Computer Science, asked by atharvmane1210, 9 months ago

Complete binary tree has n=31 nodes then its depth is​

Answers

Answered by Anonymous
6

Answer:

........................................,......................

Answered by rajivbansal0842
5

Consider how a complete binary tree of height h is constructed, one vertex at the root level, two at the first level below the root, four at the second level below, and so on, until the hth level, which has at least one vertex, but at most twice as many as the previous level. Note that the number of vertices at each level is a power of two (excluding the last, which is a special case). Then we have:

1+∑i=0h−12i≤n≤∑i=0h2i

Using the identity that the sum of the first k powers of two is 2k+1−1 we get:

1+2h−1≤n≤2h+1−12h≤n≤2h+1−1

and hence

2h≤n<2h+1

Taking the base 2 logarithm:

h≤logn<h+1

So we can conclude

h=⌊logn⌋

As logn is bigger than h, but less than the next integer h+1.

I hope this helped you...

Pls mark me as brainlist

Similar questions