#python #sicp
A common pattern can be found in the body of many recursive functions. The body
begins with a base case, a conditional statement that defines the behavior of
the function for the inputs that are simplest to process. In the case of sum_digits , the base case is any single-digit argument, and we simply return
that argument. Some recursive functions will have multiple base cases.
The base cases are then followed by one or more recursive calls. Recursive
calls always have a certain character: they simplify the original problem.
Recursive functions express computation by simplifying problems incrementally.
If you want to change selection, open document below and click on "Move attachment"
1.7 Recursive Functionstil eventually a single-digit input is reached.
This example also illustrates how functions with simple bodies can evolve
complex computational processes by using recursion.
1.7.1 The Anatomy of Recursive Functions
Video:
Show
Hide <span>A common pattern can be found in the body of many recursive functions. The body
begins with a base case, a conditional statement that defines the behavior of
the function for the inputs that are simplest to process. In the case of
sum_digits , the base case is any single-digit argument, and we simply return
that argument. Some recursive functions will have multiple base cases.
The base cases are then followed by one or more recursive calls. Recursive
calls always have a certain character: they simplify the original problem.
Recursive functions express computation by simplifying problems incrementally.
For example, summing the digits of 7 is simpler than summing the digits of 73,
which in turn is simpler than summing the digits of 738. For each subsequent
call, there is less work lef Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details