Recursion in data structure

169 views 9 slides Mar 12, 2020
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

@Recursion is a process in which a function calls itself as a subroutine. This allows the function to be repeated several times.
@Recursion property
@Tower of Hanoi


Slide Content

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.

R ecursion property Recursive procedure must have the following two properties: There must be certain criteria, called base criteria. Each time the procedure does call itself,it must be closer to the base criteria.

E xample of recursion Factorial function The product of positive integer from 1 to n is called “n factorial”. If N=0 then, When N=1 F N =1 F 1 =1*F 1-1 2) If N>0 then, F 1 =1* F F N =N* F N-1 F 1 =1 When N=0 Similarly,F 2 =2 F = 1 F 3 =6

T ower 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: .Only one disk must be moved at a time. No disk may be placed on top of a smaller disk The minimum number of moves required to solve a Tower of Hanoi

A lgorithm General notation Tower(N,BEG,AUX,END) if N>0 then Move ( N-1 ,BEG ,END ,AUX) BEG END TOWER(1,BEG,AUX,END) Move ( N-1 ,AUX ,BEG ,END) Return.

E xample of tower of Hanoi

E xample

E nd of the presentation Thank YOU