Data Structure Multiple Choice Questions on “Coin Change Problem”.
1. You are given infinite coins of denominations v1, v2, v3,…..,vn and a sum S. The coin change problem is to find the minimum number of coins required to get the sum S. This problem can be solved using ____________ Answer: b 2. Suppose you have coins of denominations 1, 3 and 4. You use a greedy algorithm, in which you choose the largest denomination coin which is not greater than the remaining sum. For which of the following sums, will the algorithm NOT produce an optimal answer? Answer: c 3. Suppose you have coins of denominations 1,3 and 4. You use a greedy algorithm, in which you choose the largest denomination coin which is not greater than the remaining sum. For which of the following sums, will the algorithm produce an optimal answer? Answer: d 4. Fill in the blank to complete the code. a) lookup[tmp] = min_coins Answer: b 5. You are given infinite coins of N denominations v1, v2, v3,…..,vn and a sum S. The coin change problem is to find the minimum number of coins required to get the sum S. What is the time complexity of a dynamic programming implementation used to solve the coin change problem? 6. Suppose you are given infinite coins of N denominations v1, v2, v3,…..,vn and a sum S. The coin change problem is to find the minimum number of coins required to get the sum S. What is the space complexity of a dynamic programming implementation used to solve the coin change problem? Answer: b 7. You are given infinite coins of denominations 1, 3, 4. What is the total number of ways in which a sum of 7 can be achieved using these coins if the order of the coins is not important? Answer: c 8. You are given infinite coins of denominations 1, 3, 4. What is the minimum number of coins required to achieve a sum of 7? Answer: b 9. You are given infinite coins of denominations 5, 7, 9. Which of the following sum CANNOT be achieved using these coins? Answer: c 10. You are given infinite coins of denominations 3, 5, 7. Which of the following sum CANNOT be achieved using these coins? Answer: d 11. What is the output of the following program? a) 2 12. What is the output of the following program? a) 2
a) Greedy algorithm
b) Dynamic programming
c) Divide and conquer
d) Backtracking
Clarification: The coin change problem has overlapping subproblems(same subproblems are solved multiple times) and optimal substructure(the solution to the problem can be found by finding optimal solutions for subproblems). So, dynamic programming can be used to solve the coin change problem.
a) 20
b) 12
c) 6
d) 5
Clarification: Using the greedy algorithm, three coins {4,1,1} will be selected to make a sum of 6. But, the optimal answer is two coins {3,3}.
a) 14
b) 10
c) 6
d) 100
Clarification: Using the greedy algorithm, three coins {4,1,1} will be selected to make a sum of 6. But, the optimal answer is two coins {3,3}. Similarly, four coins {4,4,1,1} will be selected to make a sum of 10. But, the optimal answer is three coins {4,3,3}. Also, five coins {4,4,4,1,1} will be selected to make a sum of 14. But, the optimal answer is four coins {4,4,3,3}. For a sum of 100, twenty-five coins {all 4’s} will be selected and the optimal answer is also twenty-five coins {all 4’s}.#include
b) min_coins = lookup[tmp]
c) break
d) continue
Clarification: min_coins = lookup[tmp] will complete the code.
a) O(N)
b) O(S)
c) O(N2)
d) O(S*N)
Answer: d
Clarification: The time complexity is O(S*N).
a) O(N)
b) O(S)
c) O(N2)
d) O(S*N)
Clarification: To get the optimal solution for a sum S, the optimal solution is found for each sum less than equal to S and each solution is stored. So, the space complexity is O(S).
a) 4
b) 3
c) 5
d) 6
View Answer
Clarification: A sum of 7 can be achieved in the following ways:
{1,1,1,1,1,1,1}, {1,1,1,1,3}, {1,3,3}, {1,1,1,4}, {3,4}.
Therefore, the sum can be achieved in 5 ways.
a) 1
b) 2
c) 3
d) 4
View Answer
Clarification: A sum of 7 can be achieved by using a minimum of two coins {3,4}.
a) 50
b) 21
c) 13
d) 23
Clarification: One way to achieve a sum of 50 is to use ten coins of 5. A sum of 21 can be achieved by using three coins of 7. One way to achieve a sum of 23 is to use two coins of 7 and one coin of 9. A sum of 13 cannot be achieved.
a) 15
b) 16
c) 17
d) 4
Clarification: Sums can be achieved as follows:
15 = {5,5,5}
16 = {3,3,5,5}
17 = {3,7,7}
we can’t achieve for sum=4 because our available denominations are 3,5,7 and sum of any two denominations is greater than 4.#include
b) 3
c) 4
d) 5
Answer: b
Clarification: The program prints the minimum number of coins required to get a sum of 10, which is 3.#include
b) 3
c) 4
d) 5
Answer: c
Clarification: The program prints the minimum number of coins required to get a sum of 14, which is 4.