uni 10 Flashcards

1
Q

What is recursion?

A

A programming technique where a method calls itself.

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

What are the two required parts of a recursive method?

A

A base case and a recursive call.

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

What is the base case in recursion?

A

The condition under which the recursion stops.

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

What is a recursive call?

A

A method call where the method calls itself.

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

What happens if a recursive method has no base case?

A

It results in infinite recursion (and usually a StackOverflowError).

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

What is stack overflow?

A

An error that occurs when too many recursive calls build up without returning.

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

How is recursion similar to iteration?

A

Both repeat steps; recursion uses method calls

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

When is recursion preferred over iteration?

A

When the problem is naturally recursive (like trees

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

What is the recursive case?

A

The part of the method that calls itself to solve a smaller problem.

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

What is factorial recursion?

A

A function where n! = n * (n - 1)!

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

Write a factorial recursive method.

A

int fact(int n) { if (n == 0) return 1; else return n * fact(n - 1); }

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

What is linear recursion?

A

Each call makes at most one recursive call.

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

What is binary recursion?

A

Each call makes two recursive calls (e.g.

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

What is tail recursion?

A

Recursive call is the last thing executed by the method.

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

What is the base case in factorial recursion?

A

When n == 0 or n == 1

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

Is recursion tested on the AP CSA exam?

17
Q

Can recursion be used to solve searching problems?

18
Q

What is a recursive Fibonacci implementation?

A

Each call returns fib(n-1) + fib(n-2)

19
Q

Is recursion efficient for Fibonacci?

20
Q

How do you trace recursive calls?

A

Draw a call stack or tree showing each call and return value.

21
Q

What is the biggest risk in writing recursion?

A

Forgetting the base case or not reducing the problem size.

22
Q

What is the advantage of recursion?

A

Code can be simpler for certain problems like backtracking or tree traversal.

23
Q

What types of problems are suited to recursion?

A

Divide and conquer

24
Q

Can all recursion be rewritten using loops?

25
What is a common AP-style recursion question?
Trace a method and determine output or count how many times it's called.