Page 399 - Computer science 868 Class 12
P. 399
11
RECURSION
Learning Objectives
11.1 Concept of Recursion 11.2 Types of Recursion
11.3 Simple Recursive Methods 11.4 Tower of Hanoi
You all must be familiar with the popular Japanese puzzle
game Sudoku. The purpose of this game is to fill in a 2 1 5 6 4 7 3 9 8
9 × 9 grid with digits such that each column, row, and 3 6 8 9 5 2 1 7 4
3 × 3 section contain the numbers from 1 to 9 only once.
The game starts with some of the squares of the 9 × 9 7 9 4 3 8 1 6 5 2
grid already filled in. The player has to apply his logic to
fill in the missing digits and complete the grid. We have 5 8 6 2 7 4 9 3 1
to keep in mind that any row or column or 3 × 3 cannot 1 4 2 5 9 3 8 6 7
contain digits from 1 to 9 more than once. To begin, the
player starts filling the boxes with numbers. If at any 9 7 3 8 1 6 4 2 5
point he finds, he has reached dead end, then he back
tracks to the previous steps and chooses a different 8 2 1 7 3 9 5 4 6
solution. This process continues until the correct solution
is obtained. This process of repeating the same job with 6 5 9 4 2 8 7 1 3
a different set of data is all about recursion. 4 3 7 1 6 5 2 8 9
In Java, we call methods from a different method. Sudoku
Recursion is a programming technique in which a method
calls itself. The solution of the bigger problem is expressed in terms of smaller problems until we reach the end point
or the base case.
Definition
Recursion is a programming technique in which the function calls itself repeatedly until an exit condition called the
base case is achieved.
397
Recursion 397

