cs176:501b:recursion
Recursion
Introduction
- Three basic structures in programming
- 1 - top-down execution of programs
- obvious
- 2 - selection structures
- branching of program execution based on selection (if, if-else, …)
- 3 - repetition structures
- loops
- “iteration”
- another way to do repetition: recursion
-
- Lab Activity: Write iterative and recursive versions of a method that prints the factorial of an int N,
// Method headers public void printFactorialIterative( int N ) public void printFactorialRecursive( int N ) // Calling printFactorial with input N = 4: printFactorialIterative(4); printFactorialRecursive(4); // Expected output of both methods: 4 * 3 * 2 * 1 = 24
cs176/501b/recursion.txt · Last modified: 2018/04/17 13:44 by jchung