OBJECTIVE OF PRESENTATION
• Define recursion and it’s property
• Example of recursion
• Tower of Hanoi and it’s algorithm
• Example of tower of Hanoi.
RECURSION
• Recursion is a process in which a function calls itself as a
subroutine. This allows the function to be repeated several times.
Recursion property
• Recursive procedure must have the following two properties:
1) There must be certain criteria, called base criteria.
2) Each time the procedure does call itself,it must be closer to the
base criteria.
Example of recursion
Factorial function
• The product of positive integer from 1 to n is called “n factorial”.
1) If N=0 then, When N=1
FN =1 F1 =1*F1-1
2) If N>0 then, F1 =1* F0
FN =N* FN-1 F1 =1
When N=0 Similarly,F2 =2
F0 = 1 F3 =6
Tower of Hanoi
• Tower of Hanoi is a mathematical game or puzzle. It consists of three rods,
and a number of disks of different sizes which can slide onto any rod.
Following rules:
1. .Only one disk must be moved at a time.
2. No disk may be placed on top of a smaller disk
3. The minimum number of moves required to solve a Tower of Hanoi
Algorithm
General notation
Tower(N,BEG,AUX,END)
1. if N>0 then
2. Move (N-1 ,BEG ,END ,AUX)
3. BEG END TOWER(1,BEG,AUX,END)
4. Move (N-1 ,AUX ,BEG ,END)
5. Return.
Example of tower of Hanoi
Example
End of the presentation
Thank YOU

Recursion in data structure

  • 1.
    OBJECTIVE OF PRESENTATION •Define recursion and it’s property • Example of recursion • Tower of Hanoi and it’s algorithm • Example of tower of Hanoi.
  • 2.
    RECURSION • Recursion isa process in which a function calls itself as a subroutine. This allows the function to be repeated several times.
  • 3.
    Recursion property • Recursiveprocedure must have the following two properties: 1) There must be certain criteria, called base criteria. 2) Each time the procedure does call itself,it must be closer to the base criteria.
  • 4.
    Example of recursion Factorialfunction • The product of positive integer from 1 to n is called “n factorial”. 1) If N=0 then, When N=1 FN =1 F1 =1*F1-1 2) If N>0 then, F1 =1* F0 FN =N* FN-1 F1 =1 When N=0 Similarly,F2 =2 F0 = 1 F3 =6
  • 5.
    Tower of Hanoi •Tower of Hanoi is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. Following rules: 1. .Only one disk must be moved at a time. 2. No disk may be placed on top of a smaller disk 3. The minimum number of moves required to solve a Tower of Hanoi
  • 6.
    Algorithm General notation Tower(N,BEG,AUX,END) 1. ifN>0 then 2. Move (N-1 ,BEG ,END ,AUX) 3. BEG END TOWER(1,BEG,AUX,END) 4. Move (N-1 ,AUX ,BEG ,END) 5. Return.
  • 7.
  • 8.
  • 9.
    End of thepresentation Thank YOU