AP CSA recursion flashcards

AP CSA recursion flashcards to help students master recursive programming concepts.

TigerHenry7·19 tarjetas·10 preguntas·2 vistas
APcomputer_scienceprogramming
0
Lo sé
1 / 19
0
Aprendiendo
Frente

What is recursion?

Toca para voltear
Reverso

A method where the solution to a problem depends on solutions to smaller instances of the same problem.

Toca para voltear
Lo sé
Aprendiendo

Quiz(10 preguntas)

Pregunta 1 de 10

1. What is the primary purpose of the base case in recursion?

Términos en este set(19)

What is recursion?

A method where the solution to a problem depends on solutions to smaller instances of the same problem.

Base case in recursion?

The condition under which a recursive function stops calling itself.

Difference between recursion and iteration

Recursion solves problems by calling itself, while iteration uses looping constructs.

Fill in the blank: A recursive function must have a _____ case.

base

True or false: Recursion can always replace loops.

False, because recursion can lead to greater memory usage and stack overflow.

What is a recursive call?

A call to the same function within its own definition.

Example of a recursive function:

A function to calculate factorial: factorial(n)=nfactorial(n1)\displaystyle factorial(n) = n * factorial(n-1).

What is infinite recursion?

Occurs when a recursive function does not reach a base case and calls itself indefinitely.

True or false: Recursive algorithms are always less efficient than iterative ones.

False, because some problems are more naturally solved with recursion.

When to use recursion?

Use recursion for problems with overlapping subproblems or when the problem size is unknown.

What is a stack overflow?

An error that occurs when the call stack pointer exceeds the stack bound, often due to deep recursion.

Difference between direct and indirect recursion

Direct recursion calls itself, while indirect recursion involves multiple functions calling each other.

Example of a simple recursive function?

Fibonacci sequence: f(n)=f(n1)+f(n2)\displaystyle f(n) = f(n-1) + f(n-2).

What is tail recursion?

A type of recursion where the recursive call is the last operation in the function.

True or false: Tail recursion can be optimized by the compiler.

True, because it can be transformed into iteration to save stack space.

Fill in the blank: The time complexity of a simple recursive Fibonacci is _____

exponential, O(2^n)

What does ‘divide and conquer’ mean in recursion?

A strategy of breaking problems into smaller, manageable subproblems.

What is memoization?

A technique to store results of expensive function calls and reuse them to improve efficiency.

Difference between depth-first and breadth-first search

DFS uses a stack (recursive), while BFS uses a queue (iterative).

Preguntas en este set(10)

1. What is the primary purpose of the base case in recursion?

A.To stop recursion
B.To increase recursion depth
C.To call functions
D.To initiate recursion

2. Which of the following describes a stack overflow?

A.Memory leak
B.Exceeded stack size
C.Incorrect function call
D.Optimized recursion

3. Which is NOT an example of a recursive function?

A.Factorial function
B.Fibonacci function
C.Looping through an array
D.Binary search

4. What type of recursion is optimized by compilers?

A.Direct recursion
B.Indirect recursion
C.Tail recursion
D.Infinite recursion

5. Which scenario is best suited for recursion?

A.Simple loops
B.Hierarchical problems
C.Linear search
D.Basic arithmetic

6. What is a characteristic of a non-tail recursive function?

A.Last operation is a recursive call
B.Can cause stack overflow
C.More memory efficient
D.Always terminates quickly

7. Which of the following is a result of infinite recursion?

A.Correct output
B.Stack overflow error
C.Immediate termination
D.Optimized performance

8. Which of the following is true about memoization?

A.Slows down recursion
B.Increases memory use
C.Stores previous results
D.Requires iterative approach

9. Which algorithm typically uses recursion?

A.Linear search
B.Binary search
C.Bubble sort
D.Insertion sort

10. What does 'divide and conquer' refer to in algorithms?

A.Single-threaded execution
B.Breaking problems into smaller problems
C.Immediate solutions
D.Linear algorithmic approach

Sets relacionados

Crea tu propio set de estudio

Sube un PDF, pega tus notas o describe un tema – la IA genera tarjetas, quizzes y más en segundos.