zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcardStudy GuideStudy GuideQuestion BankQuestion Bank
GlossaryGlossary

Recursion

Question 1
Computer Science AAPConcept Practice
1 mark

In a recursive method, what is the primary role of the base case?

Question 2
Computer Science AAPConcept Practice
1 mark

Which of the following best describes a recursive call?

Question 3
Computer Science AAPConcept Practice
1 mark

Consider the following recursive method:

java
public int mystery(int n) {
    if (n == 0) {
        return 0;
    } else {
        return n + mystery(n - 1);
    }
}

What is the output of mystery(3)?

Question 4
Computer Science AAPConcept Practice
1 mark

What is a potential drawback of using recursion compared to iteration?

Question 5
Computer Science AAPConcept Practice
1 mark

Given an array arr = {1, 2, 3, 4, 5}, what would be the base case for a recursive method designed to print each element of the array?

Question 6
Computer Science AAPConcept Practice
1 mark

Which of the following is a disadvantage of using recursion to traverse an array compared to using a loop?

Question 7
Computer Science AAPConcept Practice
1 mark

In a recursive binary search, what condition must be met for the algorithm to work correctly?

Feedback stars icon

How are we doing?

Give us your feedback and let us know how we can improve

Question 8
Computer Science AAPConcept Practice
1 mark

Given a sorted array arr = {2, 4, 6, 8, 10}, what would be the next step in a recursive binary search to find the target value 4?

Question 9
Computer Science AAPConcept Practice
1 mark

What is the time complexity of a recursive binary search algorithm in the best-case scenario?

Question 10
Computer Science AAPConcept Practice
1 mark

In merge sort, what is the primary purpose of the 'merge' function?