====== 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// * [[http://introcs.cs.princeton.edu/java/23recursion/|Princeton Introduction to Java Programming notes on 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 ----