Question 15Asked in UGC NET Computer Science, November 2017 (Paper II & III, Selected Questions)

Consider an array representation an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at…

Consider an array representation an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at index i of the array (i < = n), the index of the parent is :
  1. Afloor ((i + 1)/2)
  2. Bceiling ((i + 1)/2)
  3. Cfloor (i/2)
  4. Dceiling (i/2)
Show answerHide answer

Correct answer: (C) floor (i/2)

Explanation

In a binary heap stored in an array from index 1 to n, the children of index i are at 2i and 2i + 1, so the parent of the element at index i is at floor(i/2).

From UGC NET Computer Science PYQ, November 2017 (Paper II & III, Selected Questions)

This is question 15 of UGC NET Computer Science PYQ, November 2017 (Paper II & III, Selected Questions). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.