The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
0 votes

Please explain the logic behind this shortcut and when to be used?

closed as a duplicate of: Madeaeasy
asked in Algorithms by (435 points)
closed ago by | 111 views
From my observation :-  this is what they are doing.. total ways to arrange 9 numbers = 9!

For denominator, start from root node, visit every node and multiply the result with number of nodes present in that subtree.

Eg here for root node :- subtree has 9 nodes,

For left child of root :- subtree has 5 nodes,

For right child of root :- subtree has 3 nodes...

So on calculate for every node to obtain denominator.

You will get 9x5x3x3x1x1x1x1x1

Now Why are they doing this?

@Shaik Masthan @MiNiPanda

please explain this


I don't understand what formula they have used. But to find the no. of max(or min) heaps from n elements we follow this approach:

If you don't get it then I'll try to explain..


@MiNiPanda Pls explain your way.. Actually, I was able to figure out answer of the above question using permutations and combinations but I want to know the answer for any general case tree. 


In similar way, 1st draw the structure of heap with 9 elements. There will be exactly one structure possible.

$H(9)= \binom{8}{5}H(5)H(3)$

P.S. I did for min heap but same approach will be for max heap.

@Kunal Kadian ,@himgta, @Markzuck

If anyone wants to do fast. just watch that video it will you to solve the question only in one minute.

just check the beautiful explanation by KAPIL sir


Please before posting the question, should check for Duplicates.

Due to you didn't check, everyone wastes their precious time for this discussion ( due to it is already solved and discussed in very clear manner )

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

47,005 questions
51,325 answers
66,668 users