chapter
    Heaps, Priority Queues and Data Structure Operations PYQs for GATE CS

    Solve 8+ Heaps, Priority Queues and Data Structure Operations previous year questions for GATE CS with answers and detailed solutions. Free sample questions b

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    2026 Slot Set1 PYQ
    Let be an odd number greater than 100. Consider a binary minheap with elements stored in an array whose index starts from 1.

    Which of the following indices of do/does NOT correspond to any leaf node of the minheap?
    Question 2
    2025 Slot Set2 PYQ
    A meld operation on two instances of a data structure combines them into one single instance of the same data structure. Consider the following data structures:

    P: Unsorted doubly linked list with pointers to the head node and tail node of the list.

    Q: Min-heap implemented using an array.

    R: Binary Search Tree.

    Which ONE of the following options gives the worst-case time complexities for meld operation on instances of size of these data structures?
    Question 3
    2025 Slot Set1 PYQ
    Level 3: Exam Standard
    The height of any rooted tree is defined as the maximum number of edges in the path from the root node to any leaf node.

    Suppose a Min-Heap stores 32 keys. The height of is _____________. (Answer in integer)
    Question 4
    2024 Slot Set1 PYQ
    Level 3: Exam Standard

    Consider a binary min-heap containing 105 distinct elements. Let be the index (in the underlying array) of the maximum element stored in the heap. The number of possible values of is

    Question 5
    2024 Slot Set1 PYQ
    Level 4: Challenger

    An array [82, 101, 90, 11, 111, 75, 33, 131, 44, 93] is heapified. Which one of the following options represents the first three elements in the heapified array?

    Question 6
    2023 PYQ
    Level 4: Challenger

    Which one of the following sequences when stored in an array at locations forms a max-heap?

    Question 7
    2023 PYQ
    Level 4: Challenger
    Let A be a priority queue for maintaining a set of elements. Suppose A is implemented using a max-heap data structure. The operation Extract-Max(A) extracts and deletes the maximum element from A. The operation Insert(A,key) inserts a new element key in A. The properties of a max-heap are preserved at the end of each of these operations.

    When A contains n elements, which one of the following statements about the worst case running time of these two operations is TRUE?
    Question 8
    2021 Slot Set2 PYQ

    Let be a binary min-heap consisting of elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the maximum element in ?

    Free preview ends here

    Login to view the complete previous-year questions and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Heaps, Priority Queues and Data Structure Operations PYQs for GATE CS

    Solve 8+ Heaps, Priority Queues and Data Structure Operations previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Heaps, Priority Queues and Data Structure Operations

    Programming and Data Structures

    Heaps, Priority Queues & DS Operations

    From tree geometry to priority queue mastery.

    1

    Heap Structure, Height & Leaf Positions

    Complete binary tree geometry, array indexing, height formula, identifying leaves. Highest weightage in this chapter.

    2

    Heap Construction & Array Validation

    Build-heap procedure, heapify, checking if a given array forms a valid heap.

    3

    Priority Queue Operations & Heap Extrema

    Insert, extract-min or extract-max, finding extreme elements, complexity analysis.

    4

    Meld Operations & Data Structure Complexity

    Merging two heaps, comparing meld cost across data structures.

    Heap Structure, Height and Leaf Positions

    Heaps, Priority Queues & DS Operations › Topic 1

    Heap Structure, Height & Leaf Positions

    The shape of the heap determines everything you can do with it.

    What you will learn here

    • Why a heap is a complete binary tree and what that shape guarantees
    • The exact array-to-tree index mapping (parent, left child, right child)
    • How to compute heap height from in one formula
    • Which indices are internal nodes vs leaves
    • Where extreme elements can hide in a heap

    Heaps, Priority Queues and Data Structure Operations: Solved Questions with Step-by-Step Explanations (8 Problems)

    Question 1 · Programming and Data Structures · 2026_Set1 MSQ
    Let be an odd number greater than 100. Consider a binary minheap with elements stored in an array whose index starts from 1.

    Which of the following indices of do/does NOT correspond to any leaf node of the minheap?
    1. A.

    2. B.

    3. C.

    4. D.

    Question 2 · Programming and Data Structures · 2025_Set2 MCQ
    A meld operation on two instances of a data structure combines them into one single instance of the same data structure. Consider the following data structures:

    P: Unsorted doubly linked list with pointers to the head node and tail node of the list.

    Q: Min-heap implemented using an array.

    R: Binary Search Tree.

    Which ONE of the following options gives the worst-case time complexities for meld operation on instances of size of these data structures?
    1. A.

      P: , Q: , R:

    2. B.

      P: , Q: , R:

    3. C.

      P: , Q: , R:

    4. D.

      P: , Q: , R:

    Question 3 · Programming and Data Structures · 2025_Set1 NAT
    The height of any rooted tree is defined as the maximum number of edges in the path from the root node to any leaf node.

    Suppose a Min-Heap stores 32 keys. The height of is _____________. (Answer in integer)
    Correct Answer:

    5.00

    Step-by-Step Solution

    Insight: This is a direct application of the heap height formula. The height of a complete binary tree with nodes is simply .

    Exam route: The problem states the min-heap stores 32 keys. Using the height formula , we substitute . Since , . The floor of 5 is 5. The height is 5.

    Learning route:

    1. Understand the definition: The height of a rooted tree is the maximum number of edges on any path from the root to a leaf.
    2. Recall the structure of a heap: A heap is a complete binary tree. This means all levels except possibly the last are completely full, and the last level is filled from left to right.
    3. Apply the formula: For a complete binary tree with nodes, the height is given by .
    4. Calculate: Here, . We know that , so .
    5. Conclusion: The height of the min-heap is 5.
    Question 4 · Programming and Data Structures · 2024_Set1 MCQ

    Consider a binary min-heap containing 105 distinct elements. Let be the index (in the underlying array) of the maximum element stored in the heap. The number of possible values of is

    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    A

    Step-by-Step Solution

    Insight: In a min-heap, the maximum element must be located at one of the leaf nodes. The problem reduces to finding the total number of leaf nodes in a complete binary tree with 105 nodes.

    Exam route:

    1. A min-heap is a complete binary tree. The maximum element can never be an internal node because an internal node must be smaller than or equal to its children. Thus, the maximum must be a leaf.
    2. For a complete binary tree with nodes, the number of leaf nodes is .
    3. Substitute . The number of leaves is .
    4. Since all elements are distinct, the maximum element could be any of these 53 leaves. Thus, there are 53 possible values for the index .

    Learning route:

    1. Understand the min-heap property: Every parent is less than or equal to its children.
    2. Deduce the location of the maximum: If the maximum element were at an internal node, it would have to be less than or equal to its children. But it is the maximum, so it cannot be strictly less than any element. This implies it cannot have any children. Therefore, it must be a leaf.
    3. Count the leaves: In a complete binary tree represented as an array of size , the leaves occupy the indices from to .
    4. Calculate the count: The number of leaves is .
    5. Apply to : .
    Question 5 · Programming and Data Structures · 2024_Set1 MCQ

    An array [82, 101, 90, 11, 111, 75, 33, 131, 44, 93] is heapified. Which one of the following options represents the first three elements in the heapified array?

    1. A.

      82, 90, 101

    2. B.

      82, 11, 93

    3. C.

      131, 11, 93

    4. D.

      131, 111, 90

    Correct Answer:

    D

    Step-by-Step Solution

    Insight: This is a heap construction question. The array must be converted into a max-heap. We need to apply the Build-Max-Heap procedure and observe the first three elements.

    Exam route:

    1. The array is .
    2. The maximum element is 131. In a max-heap, the root must be the maximum. So will be 131. This eliminates options A and B.
    3. We apply Max-Heapify from the last internal node down to the root. The last internal node is at index .
    4. After running the full Build-Max-Heap algorithm, the root becomes 131. Through careful tracing, we find the array starts with 131, 111, 90.

    Learning route:

    1. Identify the goal: Convert the given array into a max-heap.
    2. Locate internal nodes: For , internal nodes are at indices 1 to 5. We start heapifying from index 5 down to 1.
    3. Index 5 (val 111): Children are at 10 (val 93). , so no swap.
    4. Index 4 (val 11): Children are at 8 (131) and 9 (44). Max child is 131. Swap 11 and 131. Array becomes: .
    5. Index 3 (val 90): Children are at 6 (75) and 7 (33). , so no swap.
    6. Index 2 (val 101): Children are at 4 (131) and 5 (111). Max child is 131. Swap 101 and 131. Array: . Now heapify index 4 (val 101): children 8 (11), 9 (44). Swap 101 and 44. Array: .
    7. Index 1 (val 82): Children are at 2 (131) and 3 (90). Max child is 131. Swap 82 and 131. Array: . Now heapify index 2 (val 82): children 4 (44), 5 (111). Swap 82 and 111. Array: . Now heapify index 5 (val 82): child 10 (93). Swap 82 and 93. Array: .
    8. The first three elements are 131, 111, 90.
    Question 6 · Programming and Data Structures · 2023 MCQ

    Which one of the following sequences when stored in an array at locations forms a max-heap?

    1. A.

      23, 17, 10, 6, 13, 14, 1, 5, 7, 12

    2. B.

      23, 17, 14, 7, 13, 10, 1, 5, 6, 12

    3. C.

      23, 17, 14, 6, 13, 10, 1, 5, 7, 15

    4. D.

      23, 14, 17, 1, 10, 13, 16, 12, 7, 5

    Correct Answer:

    B

    Step-by-Step Solution

    Insight: This is a heap validation question. We need to check which of the given arrays satisfies the max-heap property: every parent must be greater than or equal to its children.

    Exam route:

    1. The max-heap property requires and for all valid .
    2. We can quickly eliminate options by checking small values of .
    3. Check Option A: At , . Its children are and . Since , this violates the max-heap property. Eliminate A.
    4. Check Option C: At , . Its child is . Since , this violates the property. Eliminate C.
    5. Check Option D: At , . Its children are and . Since , this violates the property. Eliminate D.
    6. Check Option B: Every internal node is greater than or equal to its children. Specifically, 23>=17,14; 17>=7,13; 14>=10,1; 7>=5,6; and 13>=12. Option B satisfies all conditions.

    Learning route:

    1. Understand the max-heap property: For every node (from 1 to ), its value must be greater than or equal to the values of its left child () and right child (), if they exist.
    2. Systematically check each option. It is often faster to look for violations rather than verifying every single node.
    3. A violation occurs if any parent is strictly less than any of its children.
    4. By checking the internal nodes (indices 1 to 5 for a 10-element array), we can quickly identify which arrays are invalid max-heaps.
    Question 7 · Programming and Data Structures · 2023 MCQ
    Let A be a priority queue for maintaining a set of elements. Suppose A is implemented using a max-heap data structure. The operation Extract-Max(A) extracts and deletes the maximum element from A. The operation Insert(A,key) inserts a new element key in A. The properties of a max-heap are preserved at the end of each of these operations.

    When A contains n elements, which one of the following statements about the worst case running time of these two operations is TRUE?
    1. A.

      Both Extract-Max(A) and Insert(A,key) run in .

    2. B.

      Both Extract-Max(A) and Insert(A,key) run in .

    3. C.

      Extract-Max(A) runs in whereas Insert(A,key) runs in .

    4. D.

      Extract-Max(A) runs in whereas Insert(A,key) runs in .

    Correct Answer:

    B

    Step-by-Step Solution

    Insight: This is a standard complexity question for heap-based priority queues. The key is to distinguish between finding the extreme element (which is ) and extracting it while maintaining the heap property (which is ).

    Exam route: Recall the fundamental operations of a binary heap. The maximum element is always at the root, so finding it takes time. However, Extract-Max removes the root, moves the last element to the root, and performs a heapify-down operation to restore the max-heap property. This traversal goes down the height of the tree, taking time. Insert adds an element at the end and performs a heapify-up, which also takes time. Therefore, both operations run in worst-case time.

    Learning route:

    1. Identify the data structure: A max-heap implemented priority queue.
    2. Analyze Extract-Max: The max element is at index 1. We swap it with the last element, reduce the heap size, and call Max-Heapify on the root. Max-Heapify takes time proportional to the height of the tree, which is .
    3. Analyze Insert: We append the new key at the end of the array and bubble it up by comparing with its parent. This also takes time proportional to the height, .
    4. Conclusion: Both operations have a worst-case running time of .
    Question 8 · Programming and Data Structures · 2021_Set2 MCQ

    Let be a binary min-heap consisting of elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the maximum element in ?

    1. A.

    2. B.

    3. C.

    4. D.

    More previous year questions (pyqs) in this unit