Question: This homework assignment is about backtracking and max - heaps. You may write procedures in a programming language or in Cormen s pseudocode. Make sure
This homework assignment is about backtracking and maxheaps. You may write procedures in a programming language or in Cormens pseudocode. Make sure you know how Cormens pseudocode works before you begin this assignment: it may work differently from what you expect.
Questions a and b are about searching for an element in a maxheap. Unlike binary search trees, heaps are not designed to be searched. However, it is still possible to search heaps somewhat efficiently by using their mathematical properties.
a points. Suppose that A is an array whose integer elements are organized into a maxheap, and that e is an integer. Write a procedure INMAXHEAPAe that returns TRUE if e is an element of A and returns FALSE otherwise. You may use one or more helper procedures. Your procedures must not change A They must not copy A They must not use linear search. They must not visit all elements of A if possible.
b points. Can the run time of INMAXHEAP from question a be determined by the master theorem? There are three possible answers, depending on what you think run time means.
The master theorem can always be used.
The master theorem can sometimes be used.
The master theorem can never be used.
Choose the answer that you think is correct, and explain why you chose it
Questions a and b are about the backtracking procedure MAKESETS and its helper MAKINGSETS, written in Cormens pseudocode. The symbol is the empty set, and the symbol is the set union operator. The parameters n k and e are nonnegative integers. The parameter s is a set of nonnegative integers.
MAKESETSnk
MAKINGSETSnk
MAKINGSETSnkes
ifk
prints
else
foreeton
MAKINGSETSnkese
a points. What will MAKESETS print? Hint: enumerate calls to MAKINGSETS breadthfirst.
b points. Suppose that n and k are nonnegative integers. What does MAKESETSnk compute? Your answer must be one short sentence, stated in terms of n and k
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
