GATE CSE
First time here? Checkout the FAQ!
x
0 votes
170 views

What should be output for $n = 8$??

asked in DS by Boss (8.6k points)   | 170 views

1 Answer

+2 votes

In the question it is clearly mentioned as "The minimum size of an array that it may require to store a binary tree with n nodes" , In this case you need to take the best case possible that is Balanced Complete Tree

The minimum size is required is 2Hieght of Tree-1

Hieght of Tree is Log2n+1 (If you take root is in hieght 0)

The minimum size is required is 2log2(n+1) -1

 

answered by Veteran (11.5k points)  
Ok, what would be minimum size of array to store $8$ elements?? Array of size 8 is sufficient to do that. but using formula in option A, says $2^4 -1 = 15$
question ask binary tree ryt :

Take Right skew tree. how much size needed for that. 15 for N= 8 ryte. since we have to consider we find parent by using child adreess. or child address using parent.

@abcd2 See we are not storing nodes in array in linear manner

Consider we are storing root node in ith location then the left child is stored in (2i)th position and right child of that node is stored in (2i+1)th position. This rule for array representation is true for each and every child.

@Anirudh if all $n$ nodes are right skewed? then it's not 15.
Does the question says any binary tree with $n$ nodes?

Yes it will take 15 . Heap is special case of binary Tree

http://quiz.geeksforgeeks.org/data-structures-binary-trees-question-22/



Top Users May 2017
  1. akash.dinkar12

    3308 Points

  2. pawan kumarln

    1884 Points

  3. Bikram

    1656 Points

  4. sh!va

    1640 Points

  5. Arjun

    1396 Points

  6. Devshree Dubey

    1272 Points

  7. Debashish Deka

    1162 Points

  8. Angkit

    1048 Points

  9. LeenSharma

    1010 Points

  10. Arunav Khare

    754 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    742 Points

  2. pawan kumarln

    510 Points

  3. Arnab Bhadra

    490 Points

  4. bharti

    304 Points

  5. LeenSharma

    248 Points


22,832 questions
29,158 answers
65,233 comments
27,673 users