Machine-translated by Google. Questions are authored in English.
Top

Heaps and Priority Queues Questions and Answers

11.

Consider a binary max-heap implemented using an array. Which among the following arrays represents a binary max-heap ?

Exam Year(s)

Tripura Public Service Commission - 2025,

Answer: A

The max-heap is 25,12,16,8,10,13,14.

In an array heap the children of position i are at 2i and 2i + 1. Check each parent: 25 is above 12 and 16; 12 is above 8 and 10; 16 is above 13 and 14. Every parent is at least as large as its children.

The others fail: in 25,12,16,13,10,8,14 the node 12 has child 13; in 25,14,12,13,10,8,16 the node 12 has child 16; and in 25,14,12,13,10,16,8 the node 12 again has child 16.

Please log in or register to report this question.

12.

Worst case time complexity to maintain the HEAP property after extracting the minimum element from a binary MIN-HEAP ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: B

The worst case is \(\theta(\log n)\).

Extracting the minimum removes the root, moves the last element into its place, and sifts it down, swapping with the smaller child at each level. A binary heap of n elements has height \(\lfloor \log_{2} n \rfloor\), so at most about \(\log n\) swaps are needed.

\(\theta(n)\) is the cost of building a heap from scratch or of searching it, and \(\theta(n \log n)\) is heap sort, which extracts all n elements. \(\theta(n^{2})\) has no basis here.

Please log in or register to report this question.

13.

The time complexity to build a heap with a list of n numbers is

Exam Year(s)

UGC NET - 2013,

Answer: B

A heap can be built from n numbers in O(n) time, option (B), using the bottom-up method: starting from the last internal node and sifting each node down. Most nodes are near the bottom, where the sift-down is short, and the work sums as n/4 x 1 + n/8 x 2 + n/16 x 3 + ..., which is bounded by a constant multiple of n. Inserting the n numbers one at a time costs O(n log n), which is the bound in (C) and is a common mistake, but it is not the best build time. O(log n) in (A) is the cost of a single insertion, and O(n squared) in (D) is far too large.

Please log in or register to report this question.

14.

Consider the following statements for priority queue : S1 : It is a data structure in which the intrinsic ordering of the elements does determine the result of its basic operations. S2 : The elements of a priority queue may be complex structures that are ordered on one or several fields. Which of the following is correct ?

Exam Year(s)

UGC NET - 2013,

Answer: D

Both statements are correct, option (D). A priority queue is a data structure in which the intrinsic ordering of the elements, their priorities, does determine the result of its basic operations: a delete returns the element with the highest (or lowest) priority and not the oldest one. Its elements can be complex structures, such as records, which are ordered on one or several of their fields, with the key field supplying the priority. So S1 and S2 are both true, and (A), (B) and (C), which call at least one of them incorrect, are wrong.

Please log in or register to report this question.

Answer: D

In any n-element heap the number of nodes of height h is at most \(\left\lceil \frac{n}{2^{h + 1}} \right\rceil\), which is option (D). Nodes of height 0 (the leaves) are about half of all the nodes, those of height 1 about a quarter, and each further level roughly halves the count again.

For h = 0 the bound gives \(\lceil n/2 \rceil\) leaves, which is right, whereas \(\lceil n/2^{h} \rceil\) in (A) would allow n leaves. The options with 'greater than', (B) and (C), state a lower bound where an upper bound is needed.

Please log in or register to report this question.

Loading…
Tags: Heaps and Priority Queues Questions and Answers || Heaps and Priority Queues MCQ Questions and Answers || Heaps and Priority Queues GK Questions and Answers || Heaps and Priority Queues GK MCQ Questions || Heaps and Priority Queues Multiple Choice Questions and Answers || Heaps and Priority Queues GK || GK on Heaps and Priority Queues || Data Structures and Algorithms Questions and Answers || Data Structures and Algorithms MCQ Questions and Answers || Data Structures and Algorithms GK Questions and Answers || GK on Data Structures and Algorithms