edited by
21,440 views
64 64 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$. The index of the parent of element $X[i], i \neq 0$, is?

  1. $\left \lfloor \dfrac i 2 \right \rfloor$
     
  2. $\left \lceil \dfrac{i-1}{2} \right \rceil$
     
  3. $\left \lceil \dfrac i 2 \right \rceil$
     
  4. $\left \lceil \dfrac i 2 \right \rceil - 1$

6 Answers

Best answer
54 54 votes

Option is (D).

Left child of ith element will be at $2*i+1$ and right child at $2(i+1)$

edited by
14 14 votes

$Ans: D$


The value inside the node is array index

Parent of $4: \left \lceil \dfrac{i}{2} \right \rceil-1=>2-1=>1$

Parent of $3: \left \lceil \dfrac{i}{2} \right \rceil-1=>2-1=>1$

Parent of $2: \left \lceil \dfrac{i}{2} \right \rceil-1=>1-1=>0$

Parent of $1: \left \lceil \dfrac{i}{2} \right \rceil-1=>1-1=>0$

2 2 votes

If index of array start with 1 then directly divide the ith value by 2 and take floor..if index start with 0 then ceil(i/2)-1 .

1 1 vote
D is the correct answer
edited by
1 1 vote
how is this working in the case of indexing start from the 2 and if i have checked that this is working fine with the indexing starting from the o and 1 but this is not genral i hope so .
 and in case of o and 1 more formulas are also there
 ceil ((i-2)/2) and floor ((i-1)/2) (in the cases of indexing from the 0 and in case of indexing from 1 subtract 1 from the result of both)
please correct me if i am wrong.
Answer:
Position:
Show:

Related questions

58 58 votes
3 answers 3 answers
16.8k
16.8k views
Ishrat Jahan asked Nov 1, 2014
16,759 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$. If the root node is at level $0$, the le...
77 77 votes
14 answers 14 answers
38.9k
38.9k views
Ishrat Jahan asked Oct 31, 2014
38,869 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.5k
26.5k views
Ishrat Jahan asked Oct 31, 2014
26,518 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,772 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...