Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science: A Structured Programming Approach Using C1 6-9 Recursion In general, programmers use two approaches to writing repetitive algorithms.

Similar presentations


Presentation on theme: "Computer Science: A Structured Programming Approach Using C1 6-9 Recursion In general, programmers use two approaches to writing repetitive algorithms."— Presentation transcript:

1 Computer Science: A Structured Programming Approach Using C1 6-9 Recursion In general, programmers use two approaches to writing repetitive algorithms. One approach uses loops; the other uses recursion. Recursion is a repetitive process in which a function calls itself. Iterative and Recursive Definition Iterative and Recursive Solution Designing Recursive Functions Fibonacci Numbers Limitations of Recursion The Towers Of Hanoi Topics discussed in this section:

2 Computer Science: A Structured Programming Approach Using C2 FORMULA 6-1 Iterative Factorial Definition

3 Computer Science: A Structured Programming Approach Using C3 FORMULA 6-2 Recursive Factorial Definition

4 Computer Science: A Structured Programming Approach Using C4 FIGURE 6-25 Factorial (3) Recursively

5 Computer Science: A Structured Programming Approach Using C5 PROGRAM 6-24Iterative Factorial Function

6 Computer Science: A Structured Programming Approach Using C6 PROGRAM 6-25Recursive Factorial Function

7 Computer Science: A Structured Programming Approach Using C7 Every recursive call must either solve part of the problem or reduce the size of the problem. Note

8 Computer Science: A Structured Programming Approach Using C8 FIGURE 6-26 Calling a Recursive Function

9 Computer Science: A Structured Programming Approach Using C9 FIGURE 6-27 Fibonacci Numbers

10 Computer Science: A Structured Programming Approach Using C10 PROGRAM 6-26Recursive Fibonacci

11 Computer Science: A Structured Programming Approach Using C11 PROGRAM 6-26Recursive Fibonacci

12 Computer Science: A Structured Programming Approach Using C12 PROGRAM 6-26Recursive Fibonacci

13 Computer Science: A Structured Programming Approach Using C13 Table 6-2Fibonacci Run Time

14 Computer Science: A Structured Programming Approach Using C14 FIGURE 6-28 Towers of Hanoi—Start Position

15 Computer Science: A Structured Programming Approach Using C15 FIGURE 6-29 Towers Solution for Two Disks

16 Computer Science: A Structured Programming Approach Using C16 FIGURE 6-30 Towers of Hanoi Solution for Three Disks (Part I)

17 Computer Science: A Structured Programming Approach Using C17 FIGURE 6-30 Towers of Hanoi Solution for Three Disks (Part II)

18 Computer Science: A Structured Programming Approach Using C18 PROGRAM 6-27Towers of Hanoi

19 Computer Science: A Structured Programming Approach Using C19 PROGRAM 6-27Towers of Hanoi

20 Computer Science: A Structured Programming Approach Using C20 Table 6-3Tracing of Program 6-27, Towers of Hanoi

21 Computer Science: A Structured Programming Approach Using C21 6-10 Programming Example— The Calculator Program Let’s look at our calculator program one more time. In Chapter 5, we gave users the capability of selecting one of four options: add, subtract, multiply, or divide. However, if users needed to make two calculations, they had to run the program twice. We now add a loop that allows users to make as many calculations as needed.

22 Computer Science: A Structured Programming Approach Using C22 PROGRAM 6-28The Complete Calculator

23 Computer Science: A Structured Programming Approach Using C23 PROGRAM 6-28The Complete Calculator

24 Computer Science: A Structured Programming Approach Using C24 PROGRAM 6-28The Complete Calculator

25 Computer Science: A Structured Programming Approach Using C25 PROGRAM 6-28The Complete Calculator

26 Computer Science: A Structured Programming Approach Using C26 PROGRAM 6-28The Complete Calculator

27 Computer Science: A Structured Programming Approach Using C27 6-11 Software Engineering In this section, we discuss some software engineering issues related to loops. Loops in Structure Charts Determining Algorithm Efficiency Linear Loops Logarithmic Loops Nested Loops Big-O Notation Standard Measures of Efficiency Topics discussed in this section:

28 Computer Science: A Structured Programming Approach Using C28 FIGURE 6-31 Structure Chart Symbols for Loops

29 Computer Science: A Structured Programming Approach Using C29 FIGURE 6-32 Structure Chart for Process

30 Computer Science: A Structured Programming Approach Using C30 Table 6-4Analysis of Multiply / Divide Loops

31 Computer Science: A Structured Programming Approach Using C31 Table 6-5Measures of Efficiency


Download ppt "Computer Science: A Structured Programming Approach Using C1 6-9 Recursion In general, programmers use two approaches to writing repetitive algorithms."

Similar presentations


Ads by Google