(12-1) Recursion H&K Chapter 9: Instructor - Andrew S. O'Fallon Cpts 121 (April 7, 2014) Washington State University
(12-1) Recursion H&K Chapter 9: Instructor - Andrew S. O'Fallon Cpts 121 (April 7, 2014) Washington State University
H&K Chapter 9
Instructor - Andrew S. OFallon
CptS 121 (April 7, 2014)
Washington State University
C. Hundhausen, A. OFallon
C. Hundhausen, A. OFallon
described by Wirth:
C. Hundhausen, A. OFallon
C. Hundhausen, A. OFallon
Properties of Recursion
C. Hundhausen, A. OFallon
This is an example provided on p. 528 of the Hanly & Koffman text. This example
performs multiplication through addition.
return ans;
C. Hundhausen, A. OFallon
. .
m = 2,
n=3
. .
// 2nd call
. .
multiply (2, 2)
m = 2,
. .
n=2
. .
// 3rd call
. .
multiply (2, 1)
ans = 6
. .
ans = 4
ans = 2 +
2=4
ans = 2
. .
m = 2,
n=1
ans = 2
C. Hundhausen, A. OFallon
ans = 2 +
4=6
ans = 2
Next Lecture
More
recursive examples
C. Hundhausen, A. OFallon
References
J.R.
10
C. Hundhausen, A. OFallon
Collaborators
Chris
11
Hundhausen
C. Hundhausen, A. OFallon