Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. To understand recursion, you must first understand stacks.
- 2. In a stack data structure, you can only add and remove from the top of the stack.
- 3. The term for adding to a stack is pushing, while removing from a stack is popping.
- 4. Python lists can be used as a stack, with the append() method for pushing and pop() method for popping.
- 5. Function calls make use of a stack called the call stack.
- 6. The call stack pushes frame objects when functions are called and pops them when functions return.
- 7. Frame objects contain the local variables and return address for a function call.
- 8. The sys.setrecursionlimit() function can change the maximum recursion depth. The times that it’s appropriate to call this is never.
- 9. Recursive functions must always have at least one base case and at least one recursive case.
- 10. "Iterative" means the code uses a loop.
- 11. Unlike recursive algorithms, iterative algorithms will never stack overflow.
- 12. Recursion and iteration are equally powerful. There is nothing recursion can do that you can't do with a loop and a stack.
- 13. The recursive factorial solution can be confusing because code is run both before and after the recursive call.
- 14. The recursive factorial solution isn’t used in real world code because calculating large factorials results in a stack overflow.
- 15. The recursive Fibonacci solution isn’t used in real world code because calculating large Fibonacci numbers requires like trillions of years.
- 16. Recursion is a good technique to use when the problem involves tree-like data structures and back-tracking.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement