Another example of a recursive process is making paper chains.

Suppose we want to make paper chains out of paper strips like that below.

Suppose you are asked to make a paper chain of length 4.

According to the process description, you must first create a chain of length 3, then add a loop to it.

So the problem has two parts: a smaller version (n=3) of the original problem, and then a small amount of work to complete it.

That small amount of work will have to wait until the subproblem is solved.

According to the process description, you must first create a chain of length 2, then add a loop to it.

So the problem has two parts: a smaller version (n=2) of the original problem, and then a small amount of work to complete it.

Again, that small amount of work will have to wait until the subproblem is solved.

Etc... Now the problem becomes n=1.
We have come to the Base Case of the recursive process, and the problem can be solved directly, as shown to the right.

But we must complete the problems that were "put on hold," represented by the paper strips waiting to be linked in.

Complete the n=2 problem by adding a loop to the chain resulting from n=1:

Complete the n=3 problem by adding a loop to the chain resulting from n=2:

Finally, complete the n=4 problem by adding a loop to the chain resulting from n=3:

We can describe recursive processes in Racket through recursive procedures.
n! = n × (n-1) × (n-2) × ... 2 × 1

Q: What is a subproblem of the factorial problem that is of the same form?

Observations: Example:
Nested if expressions like that used in quot can be modeled using flowchart diagrams like the one below.

This ensures that exactly one among multiple possible actions is performed.

In quot:

test1: (< d 0) action1: return (- (quot n (- d)))
test2: (< n 0) action2: return (- (quot (- n) d))
test3: (< n d) action3: return 0
action4: return (+ 1 (quot (- n d) d)))
The remainder when dividing integer n by integer d is the difference between n and the product of d and the number of times d divides n, i.e. (quotient n d).

Example: the remainder when dividing 10 by 3 is:

10 - 3 × (quotient 10 3) =

10 - 9 =

1

  (define remainder
    (lambda (n d)
      (- n (* d (quotient n d)))))

General form:
 (define num-digits
   (lambda (n)
     (if _________
         _________
         _________)))