GATE CS 2024 Set 1 — Question 43
MCQ+2 / -0.67MediumMin-Heap & Max-HeapHeapsProgramming & Data Structures
Programming & Data Structures → Heaps → Min-Heap & Max-Heap
Last updated
Question
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
A.
53
B.
52
C.
27
D.
1
Correct answer
(A) 53
Solution
In a min-heap, the property is that every parent node is smaller than or equal to its children. Consequently, the smallest element is at the root, and the largest element must be one of the leaf nodes. It cannot be an internal node because an internal node must be smaller than its children.In a binary heap with distinct elements, the structure is a complete binary tree. The number of leaf nodes in a complete binary tree with nodes is given by .Given :
Number of leaves = .The maximum element can be located at any of these leaf positions. Therefore, there are 53 possible values for the index .
Number of leaves = .The maximum element can be located at any of these leaf positions. Therefore, there are 53 possible values for the index .
More questions on Heaps
2024 Set 2 Q13Consider the following C program. Assume parameters to a function are evaluated from right to left.…2024 Set 2 Q17Let be the adjacency matrix of a simple undirected graph . Suppose is its own inverse.…2024 Set 1 Q17Given an integer array of size , we want to check if the array is sorted (in either ascending or…2024 Set 1 Q18Consider the following C program: [code] Which one of the following statements is CORRECT?2024 Set 1 Q19Consider the following C program: [code] Assume that the input to the program from the command line…
Practice GATE CS PYQs with adaptive difficulty
Timed practice, skill tracking, and AI explanations — free to start.
Start practicing free