This preview shows page 1. Sign up to view the full content.
Unformatted text preview: (3) ; // writes 6 to the screen.
9 2 - If you keep deriving simpler and simpler
problems of the “same kind”, you will
eventually reach an “easy” problem.
Let’ look at factorial again, to understand
factorial(n) = n * factorial(n - 1) --- if n > 0
factorial(n) = 1
--- if n = 0
11 10 1 - factorial(n) is decomposed into two
problems: A multiplication and
factorial(n-1) is a problem of the same
kind as factorial(n), but factorial(n-1) is
also simpler then factorial(n).
2 - If we keep reducing the argument of
factorial( ) more and more, eventually,
we will get factorial(0) which is “easy”
12 Example: Writing an array backwards
Given is an array of characters, and we want
to write its elements backwards to the screen,
i.e., starting with the last character.
Of course this can be done with a
for (x = ArraySize-1...
View Full Document