Data Structures & AlgorithmsVery hard
For sorted positive integers, the smallest value that cannot be formed as a subset sum equals R+1, where R is the reach. Why does a value a > R+1 stop the reach?
- A. Because a > R+1 cannot be formed from earlier values, and every later value is at least a, so R+1 stays unreachable.
- B. Because the sum of the array becomes odd at that point.
- C. Because positive integers cannot exceed R in a sorted list.
- D. Because the reach is reset to zero whenever a value is skipped.
Correct answer: A. Because a > R+1 cannot be formed from earlier values, and every later value is at least a, so R+1 stays unreachable.
Values before a sum to at most R, so R+1 cannot be built from them; the later values are all at least a > R+1, so they cannot help either. Hence R+1 is the smallest unreachable subset sum.
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
- Items (weight, value) are [(5, 60), (4, 40), (6, 50), (3, 30), (2, 15), (7, 70)]. Each item can be taken at most once, and the total…
- A shop has these items as (weight, value, number available): [(2, 10, 2), (3, 14, 3), (5, 30, 1)]. You may take at most the listed number…
- How many subsets of [2, 3, 5, 7, 4, 1, 6, 8] (chosen by position, the empty set excluded) have a sum of exactly 10?
- The numbers [31, 26, 33, 21, 40] are split into two groups (every number goes to exactly one group). What is the smallest possible…
- Each number in [1, 2, 3, 4, 5, 6, 7] gets a sign '+' or '-', and all are then added. How many sign choices give a total of exactly 4?
- How many NON-EMPTY subsets of [4, 7, 2, 9, 5, 3, 8, 6] have a sum divisible by 3? Subsets are chosen by position.