58 58 votes An array $X$ of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is $0$. If the root node is at level $0$, the level of element $X[i]$, $i \neq 0$, is $\left \lfloor \log _2 i \right \rfloor$ $\left \lceil \log _2 (i+1)\right \rceil$ $\left \lfloor \log _2 (i+1) \right \rfloor$ $\left \lceil \log _2 i \right \rceil$ Data Structures gateit-2006 data-structures binary-tree normal + – Ishrat Jahan 16.9k views answer comment Share Follow Print See all 7 Comments 7 7 Comments reply Show 4 previous comments jatin kumar 3 commented May 25, 2018 reply Follow flag root node is always at Level 1.How level 0 come at root ? 0 0 replyShare Chawlaajay commented Sep 19, 2018 reply Follow flag Can any one explain the concept of flooring? 0 0 replyShare `JEET commented Jan 15, 2019 reply Follow flag @Chawlaajay Just take the lower integer value. for example floor of 4.4 is 4. (Since, we have to take the lower integer value). Similarly, floor of -4.4 is -5. (Since, -5 is smaller than -4) 2 2 replyShare Please log in or register to add a comment.
Best answer 50 50 votes PS : the value inside the node is array index FALSE , $\left \lfloor \log _2 i \right \rfloor = \left \lfloor \log _2 1 \right \rfloor = 0 $ but $X[1]$ is at level $1$ FALSE , $\left \lceil \log _2 (i+1) \right \rceil = \left \lceil \log _2 (4+1) \right \rceil = \left \lceil \log _2 (5)\right \rceil = 3 $ but $X[4]$ is at level $2$ Correct FALSE , $\left \lceil \log _2 i \right \rceil = \left \lceil \log _2 1 \right \rceil = 0 $ but $X[1]$ is at level $1$ Gate Ranker18 answered Aug 21, 2017 • edited Jun 28, 2019 by Lakshman Bhaiya Gate Ranker18 comment Share Follow See all 10 Comments 10 10 Comments reply Show 7 previous comments Arjun commented Dec 12, 2021 reply Follow flag You have to use the definition of complete binary tree based on the context. A heap is a complete binary tree or almost complete binary tree? 2 2 replyShare Roshni22 commented Dec 12, 2021 reply Follow flag Okay sir, got it. Heap is a almost complete binary tree as per CLRS but in some other text it’s considered complete binary tree. I understood what you are trying to imply. 1 1 replyShare Roshni22 commented Dec 12, 2021 i edited by Roshni22 Dec 12, 2021 reply Follow flag On above grounds can https://gateoverflow.in/663/Gate-cse-2000-question-2-16: question be considered ambiguous? Since on basis of definition we can have B or D as answers. Which one should we consider in such cases as per your opinion. 0 0 replyShare Please log in or register to add a comment.
36 36 votes Hope it helps. krish__ answered Nov 19, 2017 krish__ comment Share Follow See all 3 Comments 3 3 Comments reply Jen_20 commented Nov 19, 2017 reply Follow flag Nice Explanation 0 0 replyShare lakshaysaini2013 commented Aug 2, 2019 reply Follow flag nice ans. 0 0 replyShare gopal_gate commented Oct 6, 2025 reply Follow flag Fill the secold last level $+$One node at last level $\leq$ Total nodes in Complete Binary Tree $(2^0+2^1+....+2^{l-1})+1\leq(i+1)$ [As index starts from $0$] $\implies2^{l}-1+1\leq i+1 \implies l\leq log_2(i+1)$ 0 0 replyShare Please log in or register to add a comment.
24 24 votes Floor(log(i+1)) draw the tree and realise that the last element at each level is the best choice to arrive at a conclusion Bhagirathi answered Nov 3, 2014 Bhagirathi comment Share Follow See all 3 Comments 3 3 Comments reply tiger commented Dec 14, 2015 reply Follow flag C is ans 0 0 replyShare Tuhin Dutta commented Aug 15, 2017 reply Follow flag why not option d)? Please explain 0 0 replyShare sid1221 commented Oct 26, 2017 reply Follow flag for index 1 it wil give 0 level which is not correct 0 0 replyShare Please log in or register to add a comment.