5.1 Thinking Recursively Flashcards

1
Q

What is recursion?

A

Recursion is a function to solve itself.

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

What does recursion need?

A

A base case.

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

What is a base case?

A

Something that causes the loop to stop. So that it doesn’t get locked and use all of system resources.

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

What is the base case in this code?

A

if n==1

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

What is the difference between recursion and iteration??

A

an iterative function is one that loops to repeat some part of the code, and a recursive function is one that calls itself again to repeat the code.

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

What are the rules of recursion?

A

The size of the problem must get smaller
There is a general case
There is a base case

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

Why must recursion problems get smaller?

A

So that the loop doesn’t use all system resources.

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

What is a general case?

A

the case for which the solution is expressed in terms of a smaller version of itself. In other words elif and else.

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

What are the positives of recursion?

A

Less code required to do a task.
Easier to understand and debug.

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

What are the negatives of recursion?

A

Recursion always requires more memory.
Danger of stack overflow if base case isn’t there or too high.
Usually slower

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

How is recursion helpful in a binary array?

A

Because you are repeating a process.

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

What is required when using recursion in a binary search?

A

Discarding half the array when it is not needed, each time to reduce size.

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

What is recursion in code?

A

If/else

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

What is iteration in code?

A

For loop.

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

What is another name for iteration?

A

Nested loop

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

When does iteration start?

A

At 0 until the number of required cycles.

17
Q

Code a five repeating for loop:

A
18
Q

In a for loop Index (i) can only be compared to what data type?

A

Integer