Question: 5 5 ) Let ( A [ 1 . . n ] ) contain ( n ) positive distinct integers in
Let A n contain n positive distinct integers in the range leftldots nright And let V be a target value. In this exercise, you are to decide which of three proposed codes solve the following problem: Present a pseudocode to compute the number of different coin collections that sum up to equal V when the collections are formed by using
or copies of A ; or copies of A ; or copies of A ; cdots ; or copies of An In parts i i i and i i i three different candidate adaptations of the standard program below are proposed. At least one is correct, and at least one is incorrect.
For each part, state if its adaptation is correct or incorrect. IN ADDITION, explain why each adaptation is wrong or right. The explanation can be brief: it counts some coin collections more than once because or it fails to count some coin colections because or it works because
The purpose of this problem is to enhance your ability to think though what is happening, and think about the timing of the executions and what might go wrong. It is not an exercise to "solve" via implementation. Indeed, it is better to think more, get the answer wrong, and learn from your mistake when you see the solution that get the write answer based on running codes.
Each proposed solution adapts a standard BFSstyle subset sum count the ways program," which is reproduced here. So count j stores the number of coin collections whose coins have been found so far to add up to equal j But it is more convenient to think of count as storing the many distinct coin collections instead of how many have been found.
For each part below, state if its adaptation is correct or incorrect. IN ADDITION, explain why each INCORRECT adaptation is wrong. Likewise, give a brief justification about why each answer that you believe to be correct is actually correct. The proposed modifications are described below.
Create the new coin value array B n where B i equals Ai and B i equals Ai for icdots n
Run the program once for the coin values mathrmBmathrmn
Correct, or Incorrect, and Why it is correct or incorrect?
Run the program once, but include the changes:
insert a line ie between lines and which reads: if j C then count jleftarrow operatornamecountjoperatornamecountj C endif.
insert the line: increment count C right after line which says: increment operatornamecountC
Correct, or Incorrect, and Why it is correct or incorrect?
Run the program twice, but but include the following changes:
Omit the print statement in line for the first run.
For the second run, omit the initialization of count in line
For the second run, omit line which says: increment Kcount C; the second run forces count C to count two C coins.
Correct, or Incorrect, and Why it is correct or incorrect?
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
