Skip to content
GATEiit

GATE CSE 2018 Q56: Number of distinct min-heaps on the values 1 to 7

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 {1,2,3,4,5,6,7} exactly once is _____.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
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.

Concept notes

Loading notes…

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

WhatsAppDownload image

Source: official GATE 2018 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key