• edited by
16,850 views
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

  1. $\left \lfloor \log _2 i \right \rfloor$ 
  2. $\left \lceil \log _2 (i+1)\right \rceil$
  3. $\left \lfloor \log _2 (i+1) \right \rfloor$ 
  4. $\left \lceil \log _2 i \right \rceil$

3 Answers

Best answer
50 50 votes

PS : the value inside the node is array index

  1. FALSE , $\left \lfloor \log _2 i \right \rfloor = \left \lfloor \log _2 1 \right \rfloor  = 0 $ but $X[1]$ is at level $1$
  2. 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$
  3. Correct
  4. FALSE , $\left \lceil \log _2 i \right \rceil = \left \lceil \log _2 1 \right \rceil  = 0 $ but $X[1]$ is at level $1$
• edited by
36 36 votes

Hope it helps.

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
Answer:
Position:
Show:

Related questions

64 64 votes
6 answers 6 answers
21.5k
21.5k views
Ishrat Jahan asked Nov 1, 2014
21,547 views
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$. The index of the parent of element $X[...
77 77 votes
14 answers 14 answers
39.0k
39.0k views
Ishrat Jahan asked Oct 31, 2014
39,031 views
In a binary tree, the number of internal nodes of degree $1$ is $5$, and the number of internal nodes of degree $2$ is $10$. The number of leaf nodes in the binary tree i...
38 38 votes
6 answers 6 answers
26.6k
26.6k views
Ishrat Jahan asked Oct 31, 2014
26,556 views
Suppose that we have numbers between $1$ and $100$ in a binary search tree and want to search for the number $55$. Which of the following sequences CANNOT be the sequence...
36 36 votes
6 answers 6 answers
17.8k
17.8k views
Ishrat Jahan asked Oct 31, 2014
17,827 views
Which of the following statement(s) is TRUE?A hash function takes a message of arbitrary length and generates a fixed length code.A hash function takes a message of fixed...