Recursion Definitions: A recursive function is a function that calls itself. Every recursive function has a base case and a recursive case. Recursive case must get closer to the base case. Examples: - factorial function - searching a maze - fibonacci function input: int, example: 123456789 output: reversed number: 987654321 pseudocode: printrec n: if (n > 0) { print last digit printrec n / 10 } c++: void printrec(int n) { if (n > 0) { cout << n%10; printrec(n/10); } } input: number as int (ex: 12345678) out: number forward void printfrec(int n) { if (n > 0) { printfrec(n/10); cout << n%10; } } input: number as int (ex: 123) output: print this number on screen vertically! 1 2 3 void printfrecv(int n) { if (n > 0) { printfrecv(n/10); cout << n%10 << endl; } } input: number as int (ex: 123) output: number backwards and forward: (32123) void printbackandforth(int n) { if (n > 9) { cout << n%10; printbackandforth(n/10); cout << n%10; } else cout << n; } void bla1() { cout << "hello" << endl; cout << "world" << endl; } void bla() { cout << "this" << endl; bla1(); cout << "test" << endl; } ... bla() ... try and implement recursively: - print number backwards - print number forward vertically - print number down and up (32123) example for maze running: try (position) { if (!marked(position)) { mark position; try (position north); try (position south); try (position east); try (position west); unmark position } }