What is recursion?
Recursion is a problem-solving technique in which a method calls itself to solve a smaller version of the same problem.
Study Java Recursion: Tracing and Algorithms with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is recursion?
Recursion is a problem-solving technique in which a method calls itself to solve a smaller version of the same problem.
What two cases must a recursive method normally contain?
A base case stops further recursive calls; a recursive case calls the same method on a smaller or simpler problem.
Why must each recursive call make progress?
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.
What does factorial(4) return if factorial(0) returns 1?
24. The calls reduce as factorial(4) = 4 × factorial(3) = 4 × 3 × 2 × 1 × factorial(0), and factorial(0) returns 1.
How does the call stack handle recursive calls?
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.
What does printUp(3) print?
It prints 1 2 3. Because printing occurs after the recursive call, the output happens while the calls return.
What does countChar("banana", 'a') return?
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.
What does arraySum({4, 7, 2}, 0) return?
13. arraySum adds values[0], values[1], and values[2], then reaches the base case when index equals values.length.
Where does binary search find 25 in {3, 8, 12, 17, 25, 31, 40}?
4. Binary search checks indices 3, 5, and then 4; values[4] is 25.
What is the main structure of merge sort?
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.
What does reverse("cat") return?
"tac". reverse removes the first character, reverses the remainder, and appends the removed character at the end.
What does isPalindrome("racecar") return?
true. The method compares matching outer characters, then recursively checks the smaller middle substring until reaching a string of length one.
A progressive guide to how computing reshapes culture, economic life, public institutions, and individual opportunities, with frameworks for evaluating digital equity, bias, cybersecurity, encryption, and collective participation.
A medium-difficulty assessment of programming fundamentals, algorithmic problem solving, control flow, data structures, testing, debugging, complexity, and decidability. Questions progress from foundational understanding to applied reasoning.
A 14-question quiz on the social, economic, privacy, informational, health, and environmental risks of computing innovations, including strategies for responsible design and oversight.
A practical guide to recognizing cybersecurity threats, protecting accounts and devices, and responding safely when information or systems may be compromised.
A guided introduction to how encryption, authentication, hashing, secure protocols, and key management establish confidentiality, integrity, privacy, and trust while creating practical and legal trade-offs.
A focused review of propositional logic, quantifiers, sets, relations, functions, and foundational proof methods in discrete mathematics for computer science.
A practical guide to evaluating computing innovations by examining their benefits, risks, equity, security, participation, and long-term effects on people and communities.
A medium-difficulty quiz on integrating problem definition, representation, algorithms, complexity analysis, testing, correctness, ethical evaluation, and documentation in a computer science capstone.
A progressive guide to designing, operating, and testing systems that continue useful service despite component faults, overload, data loss, and recovery challenges.
A medium-difficulty quiz on how independently operated networks, protocols, addresses, naming systems, transport services, and routing mechanisms work together to form the Internet.
A progressive guide to how packet-switched networks encapsulate data, move it across links, and manage delay, throughput, queues, and congestion.
A structured guide to designing parallel and distributed systems through decomposition, communication, coordination, state management, scalability, and fault tolerance.