Intro to CS: Lecture 15 - Recursion
Topics: Recursion: iteration vs. recursion, inductive reasoning
Recursion is review for me. I like the example she gave with the student asking professor, TA, and LA to regrade.
Big idea: “Earlier” function calls are waiting on results before completing. Went over some more examples of recursion.
When to use recursion?
- Multiplication of two numbers did not need a recursive function, did not even need an iterative function
- Factorial was a little more intuitive to implement with recursion
- MOST problems do not need recursion to solve them
- If iteration is more intuitive for you then solve them using loops
- SOME problems yield far simpler code using recursion
- Searching file system for a specific file
- Evaluating mathematical expressions that use parens for order of ops