Recursion - ISC Class 12 Computer Science Notes, Diagrams and Solved Questions

Solve problems by calling a method on smaller versions of themselves: base cases, the call stack, factorial, GCD, recursive binary search, base conversion, String recursion and the Tower of Hanoi.

In this chapter

  • Turn a recursive definition into a Java method with a base case
  • Trace winding and unwinding on the call stack
  • Find a GCD with Euclid's rule and an LCM from it
  • Write binary search recursively
  • Convert numbers between bases with recursion
  • Reverse Strings and test palindromes recursively
  • Solve the Tower of Hanoi and show it needs 2ⁿ − 1 moves
  • Spot infinite recursion and StackOverflowError