0% found this document useful (0 votes)
2 views36 pages

Chapter1d Recursion

The document reviews class exercises focused on identifying and correcting errors in C programming statements, followed by an introduction to recursion using the factorial algorithm as a case study. It discusses designing recursive algorithms, their limitations, and presents examples such as the Greatest Common Divisor, Fibonacci Numbers, and the Towers of Hanoi. The content emphasizes the analytical approach to recursion and highlights when recursion is an appropriate solution.

Uploaded by

derilas147
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views36 pages

Chapter1d Recursion

The document reviews class exercises focused on identifying and correcting errors in C programming statements, followed by an introduction to recursion using the factorial algorithm as a case study. It discusses designing recursive algorithms, their limitations, and presents examples such as the Greatest Common Divisor, Fibonacci Numbers, and the Towers of Hanoi. The content emphasizes the analytical approach to recursion and highlights when recursion is an appropriate solution.

Uploaded by

derilas147
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

REVIEW OUR LAST CLASS

1
Exercise…
Identify and correct the errors in each of the following
statements:

a) printf(“The value is %d\n”, &number);


b) scanf(“%d%d”, &number1, number2);
c) if(c<7);{
printf(“C is less than 7\n”);}
d) if(c=>7){
printf(“C is equal to or less than 7\n”);}
2
RECURSION

3
Factorial - A Case Study

We begin the discussion of recursion with a


case study and use it to define the concept.
This section also presents an iterative and a
recursive solution to the factorial algorithm.

• Recursive Defined
• Recursive Solution
Factorial
Factorial
Factorial
Factorial
Factorial
Factorial
Designing Recursive Algorithms

In this section we present an analytical


approach to designing recursive algorithms.
We also discuss algorithm designs that are
not well suited to recursion.

• The Design Methodology


• Limitation of Recusion
• Design Implementation
Algorithm Print Reverse
Recursive Examples

Three recursive programs are developed and


analyzed. Only one, the Towers of Hanoi,
turns out to be a good application for
recursion.
• Greatest Common Divisor
• Fibonacci Numbers
•The Towers of Hanoi
GCD
GCD
Fibonacci
Fibonacci
Fibonacci
Fibonacci Numbers

f(n) = f(n-1) + f(n-2)


f(0) = 1
f(1) = 1

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987…
Towers of Hanoi
Towers of Hanoi
Recursion Example

35
TQ

36

You might also like