GATE CSE 2018 Q56: Number of distinct min-heaps on the values 1 to 7
- Programming and Data Structures
- 2 marks
- NAT
- No negative marking
Syllabus topics: Trees, binary search trees and binary heaps; Combinatorics: counting, recurrence relations and generating functions
Question
The number of possible min-heaps containing each value from exactly once is _____.
Try it: numerical answer: type the value
Show answer and explanation
Answer: 80 (official GATE 2018 final answer key)
Concept used: A heap on 7 keys is a complete binary tree with 3-node subtrees; the minimum is fixed at the root and the remaining keys are split between the subtrees, each of which must itself be a heap.
First step: Put 1 at the root, choose which 3 of the remaining 6 values go to the left subtree, and multiply by the number of heaps possible on each 3-element subtree.
Full step-by-step solution
Loading…
Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.
More questions on Trees, binary search trees and binary heaps
Every PYQ on this topic →Share this question
Source: official GATE 2018 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key
More Programming and Data Structures PYQs
- 2026 Session 1 · Q23Non-leaf indices in a 1-indexed binary heap with n odd
- 2026 Session 1 · Q24Empty slots after linear-probing inserts with h(x) = (x+7) mod 11
- 2026 Session 1 · Q33Maximum height of a full binary tree with 23 nodes
- 2026 Session 1 · Q34Output of a C function with a shadowed block variable
- 2026 Session 1 · Q39Recursive length of a non-empty singly linked list
- 2026 Session 1 · Q40Third insertion that can never yield a complete BST of 1..15