Recursion Flashcards
1
Q
Recursive Mindset
A
- no for/while loops
- no list comprehensions
- no builtins like min, sum, len
- have def and return
2
Q
Elements of recursion
A
- solve problem in divide and conquer manner
1. recursive function call(s) on smaller inputs
2. reachable base case to ensure calculation halts - based on solving smaller instances of the same big problem
3
Q
Linear search
A
- match element to be searched with entire list of elements
- brute force
4
Q
Binary search
A
- used to find item in ordered list
- search sorted array by repeatedly dividing search interval in half
5
Q
When to use recursion
A
when number of loops cannot be determined beforehand
6
Q
Head recursion
A
Recurse then local calculation
7
Q
Tail recursion
A
Local calculation then recurse