Recursion vs Iteration
Today I learned Chapter 2 : Recursion vs Iteration from The Recursive Book of Recursion book.
- every iteration can be converted into recursion, and vice versa.
- use
callStackto demonstrate recursion in the iteration. - recursion mostly only used on : tree, backtracking, not deeply recursive to cause a stack overflow. otherwise, use recursive instead.
- for example : maze, compiler (bcs programming language can break source code into a tree structure)
- to create recursion : identify the recursive case and base case. it can be by top-down approach (breaking problem into subproblem until found the basecase) or botom-up aproach (set base case first then see how larger problems are constructed from there).