Data Structures & AlgorithmsHardProduct-company placement

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

  1. A. 8
  2. B. 44
  3. C. 24
  4. D. 52

Correct answer: B. 44

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic