Data Structures & AlgorithmsHardGATE CS · Product-company placement

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

  1. A. 3
  2. B. 8
  3. C. 10
  4. D. 13

Correct answer: C. 10

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic