Recursion Flashcards

1
Q

Recursive Mindset

A
  1. no for/while loops
  2. no list comprehensions
  3. no builtins like min, sum, len
  4. have def and return
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Linear search

A
  • match element to be searched with entire list of elements

- brute force

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Binary search

A
  • used to find item in ordered list

- search sorted array by repeatedly dividing search interval in half

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When to use recursion

A

when number of loops cannot be determined beforehand

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Head recursion

A

Recurse then local calculation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Tail recursion

A

Local calculation then recurse

How well did you know this?
1
Not at all
2
3
4
5
Perfectly