Free Online Flashcard Deck

Java Recursion: Tracing and Algorithms Free Online FlashCards

Study Java Recursion: Tracing and Algorithms with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is recursion?

Back

Recursion is a problem-solving technique in which a method calls itself to solve a smaller version of the same problem.

02
Front

What two cases must a recursive method normally contain?

Back

A base case stops further recursive calls; a recursive case calls the same method on a smaller or simpler problem.

03
Front

Why must each recursive call make progress?

Back

The recursive case must move the argument or range closer to the base case. Otherwise, the method may never terminate and can cause a StackOverflowError.

04
Front

What does factorial(4) return if factorial(0) returns 1?

Back

24. The calls reduce as factorial(4) = 4 × factorial(3) = 4 × 3 × 2 × 1 × factorial(0), and factorial(0) returns 1.

05
Front

How does the call stack handle recursive calls?

Back

Each recursive call creates a new stack frame with its own parameters and local variables. Calls descend toward the base case, then suspended calls finish as returns move upward.

06
Front

What does printUp(3) print?

Back

It prints 1 2 3. Because printing occurs after the recursive call, the output happens while the calls return.

07
Front

What does countChar("banana", 'a') return?

Back

3. The method examines the first character, adds 1 when it matches 'a', and recursively processes the remaining substring until it reaches the empty string.

08
Front

What does arraySum({4, 7, 2}, 0) return?

Back

13. arraySum adds values[0], values[1], and values[2], then reaches the base case when index equals values.length.

09
Front

Where does binary search find 25 in {3, 8, 12, 17, 25, 31, 40}?

Back

4. Binary search checks indices 3, 5, and then 4; values[4] is 25.

10
Front

What is the main structure of merge sort?

Back

Merge sort recursively sorts the left and right halves, then merges those sorted halves. Its base case is a portion with zero or one element.

11
Front

What does reverse("cat") return?

Back

"tac". reverse removes the first character, reverses the remainder, and appends the removed character at the end.

12
Front

What does isPalindrome("racecar") return?

Back

true. The method compares matching outer characters, then recursively checks the smaller middle substring until reaching a string of length one.