The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
86 views
What must be the ideal size of array if the height of tree is ‘l’?
a) 2l-1
b) l-1
c) l
d) 2l

 

in Programming by Active (1.2k points) | 86 views
+1
Can you tell, how you have defined height, root at height 0 or 1

2 Answers

+1 vote
Assuming root at height 1

Since maximum elements in a tree (complete binary tree) of height l will be (2^l)-1 so a good array size must be that (since a binary tree node may not always have 2 children but for safety we should take it).

Therefore, none of your answer is correct it should be (2^l) -1
by Loyal (5.5k points)
edited by
+1 vote
Answer will be $2^{l}-1$ if you consider the array indexing starting from 1

At height l=1--$2^1-1$ only one node

l=2  -- $2^2-1$node

At l height max node will be $2^l-1$

So this is max size of array that would be required
by Loyal (5.5k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,339 questions
55,765 answers
192,355 comments
90,817 users