Given the integers from 1 to n, determine how many valid binary heaps can be constructed with these numbers.
Example: 1 2 3 4
valid min heaps are: {1 2 3 4}, {1 3 2 4}, {1 2 4 3},
Thus the answer is 3
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
hint:
A binary heap has a predefined number of nodes, and a well defined structure (Complete tree)
Think recursively about this problem.
“Chose” which of the non-root numbers go to the left subtree, and which to the right – and recursively invoke on the subtrees.
The question is tagged as homework, so I am leaving finding the exact numbers for the general case up to you.