LearnFrenzy
Sign in Take a free test

Data Structures in Java · Data Structures in Java MCQ · Question 7

Child indexes in an array-based binary heap Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 7 Back to Exercise

In a binary heap stored in a 0-based array, where are the children of the node at index i?

  • A i + 1 and i + 2
  • B 2i and 2i + 1
  • C 2i + 1 and 2i + 2 Correct
  • D i / 2 and i / 2 + 1
Correct Answer: Option C

The parent of index i is (i − 1) / 2. (2i and 2i + 1 is the 1-based layout.)

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links