Data Structures & AlgorithmsHardTCS NQT · GATE CS
Assertion (A): The greedy 'largest coin first' is optimal for the coin set {1, 3, 4} when the amount is 6. Reason (R): A coin system whose denominations are each a multiple of the previous one (such as 1, 5, 25) is canonical, and greedy is optimal for canonical systems.
- A. Both A and R are true, and R explains A
- B. A is true, but R is false
- C. A is false, and R is true but does not apply to this coin set
- D. Both A and R are false, and R is true only for coin sets of size two
Correct answer: C. A is false, and R is true but does not apply to this coin set
Greedy gives 4 + 1 + 1 = 3 coins for 6, while 3 + 3 uses 2, so A is false. R is a true property of canonical systems, but {1, 3, 4} is not a chain of multiples, so R does not apply.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Which of the following statements about the sliding window technique on arrays with NEGATIVE numbers is/are correct? I. A plain…
- The array [7, 2, 5, 10, 8, 3, 6] must be split into exactly 3 contiguous non-empty parts (order kept). What is the smallest possible value…
- An array has 10^5 values and you need the k-th smallest value among all pair sums a[i] + a[j] with i < j. Which approach is the right fit?
- From [4, 9, 2, 7, 5, 1] you may pick any elements (each at most once). What is the minimum number of picks so that the picked sum is at…
- How many index triples i < j < k in [-2, -1, 0, 1, 2, 3] have a sum of exactly 0?
- How many contiguous subarrays of [1, 2, 3, 4] have a sum that is a perfect square?