Data Structures & AlgorithmsHardGATE CS

Using parts 3, 4, 5 (each any number of times), in how many ways can 10 be written as an ORDERED sum (so 1 + 2 and 2 + 1 count separately)?

  1. A. 4
  2. B. 2
  3. C. 3
  4. D. 6

Correct answer: A. 4

Ordered sums: f(n) = Σ f(n − c) over parts c, f(0) = 1, giving 4. Putting the coin loop OUTSIDE the amount loop counts unordered combinations instead (2).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic