In an array-based implementation of a complete binary tree, what is the index of the left child of a node at index i (assuming zero-based indexing)?


A

2i

B

2i + 1

C

i + 1

D

i - 1

উত্তরের বিবরণ

img

Answer: )  2*i + 1

The usual mapping (zero-based arrays)
When a binary tree is stored in an array arr[] with root at index 0, the index formulas are:

Left child of node at index i → left = 2*i + 1
Right child of node at index i → right = 2*i + 2
Parent of node at index i (i > 0) → parent = floor((i - 1) / 2)

Example: arr = [A, B, C, D, E, F, G] (indices 0..6)


index: 0 1 2 3 4 5 6
value: A B C D E F G

Tree:
  

Check: left child of i=1 is 2*1+1=3 → D (correct).     
           Right = 2*1+2=4 → E.

One-based indexing alternative
If the array is one-based (root at index 1), the formulas shift:

Left = 2*i++ 1
Right = 2*i + 2
Parent = floor(i / 2)

 

Unfavorite

0

Updated: 2 days ago

Related MCQ

For BFS of a graph, we should use: 

Created: 2 days ago

A

queue

B

Stack

C

priority queue

D

stack.

Unfavorite

0

Updated: 2 days ago

Newton's backward interpolation formula is the most effective when:

Created: 2 days ago

A

Interpolation point is near the beginning 

B

Interpolation point is near the end

C

Data points are not equally spaced

D

Function is non-polynomial

Unfavorite

0

Updated: 2 days ago

The bisection method is used to: 

Created: 2 days ago

A

Find the eigenvalue of a matrix

B

Solve a system of linear equation

C

Find roots of non-linear equations

D

Perform numerical integration

© LXMCQ, Inc. - All Rights Reserved

Developed by WiztecBD