Examveda

For construction of a binary heap with property that parent node has value less than child node. In reference to that which line is incorrect. Line indexed from 1.
1. add(int k)
2. {
3.     heap_size++; 
4.     int i = heap_size - 1;
5.     harr[i] = k;
6.     while (i != 0 && harr[parent(i)] < harr[i])
7.     {
8.             swap(&harr[i], &harr[parent(i)]);
9.             i = parent(i);
10.    }
11. }

A. Line - 3

B. Line - 5

C. Line - 6

D. Line - 7

Answer: Option C


This Question Belongs to Data Structure >> Heaps

Join The Discussion

Related Questions on Heaps

Which of the following is true for a min-heap?

A. The root node is the smallest element, and every parent node is smaller than its children.

B. The root node is the largest element, and every parent node is larger than its children.

C. All nodes are arranged in a complete binary tree.

D. The tree is always balanced.