Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley CHAPTER 2 Recursion:

Similar presentations


Presentation on theme: "Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley CHAPTER 2 Recursion:"— Presentation transcript:

1 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley CHAPTER 2 Recursion: The Mirrors DATA ABSTRACTION AND PROBLEM SOLVING WITH C++ WALLS AND MIRRORS Third Edition Frank M. Carrano Janet J. Prichard Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley

2 Figure 2-1 A recursive solution

3 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-2 fact(3)

4 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-3 A box

5 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-4 The beginning of the box method

6 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-5a Box trace of fact(3)

7 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-5b Box trace of fact(3)

8 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-5c Box trace of fact(3)

9 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-6 A recursive solution

10 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-7a Box trace of writeBackward("cat", 3)

11 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-7b Box trace of writeBackward("cat", 3)

12 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-7c Box trace of writeBackward("cat", 3)

13 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-8a Box trace of writeBackward("cat", 3) in pseudocode

14 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-8b Box trace of writeBackward("cat", 3) in pseudocode

15 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-8c Box trace of writeBackward("cat", 3) in pseudocode

16 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-8d Box trace of writeBackward("cat", 3) in pseudocode

17 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-8e Box trace of writeBackward("cat", 3) in pseudocode

18 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-8f Box trace of writeBackward("cat", 3) in pseudocode

19 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-9a Box trace of writeBackward("cat", 3) in pseudocode

20 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-9b Box trace of writeBackward("cat", 3) in pseudocode

21 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-9c Box trace of writeBackward("cat", 3) in pseudocode

22 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-9d Box trace of writeBackward("cat", 3) in pseudocode

23 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-9e Box trace of writeBackward("cat", 3) in pseudocode

24 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-10 Recursive solution to the rabbit problem

25 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-11 The recursive calls that rabbit(7) generates

26 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-12 The recursive calls that c(4, 2) generates

27 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-13 Recursive solution to the largest-item problem

28 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-14 The recursive calls that maxArray( ) generates

29 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-15a Box traces of binarySearch with anArray = : (a) a successful search for 9

30 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-15b Box traces of binarySearch with anArray = : (b) an unsuccessful search for 6

31 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-16 Box method with a reference argument

32 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-17 A sample array

33 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-18 A partition about a pivot

34 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-19a and 2-19b (a) The initial state; (b) move n – 1 disks from A to C

35 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-19c and 2-19d (c) move one disk from A to B; (d) move n – 1 disks from C to B

36 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-20 The order of recursive calls that results from solveTowers(3, A, B, C)

37 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-21a Box trace of solveTowers(3,'A', 'B', 'C')

38 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-21b Box trace of solveTowers(3,'A', 'B', 'C')

39 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-21c Box trace of solveTowers(3,'A', 'B', 'C')

40 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-21d Box trace of solveTowers(3,'A', 'B', 'C')

41 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-21e Box trace of solveTowers(3,'A', 'B', 'C')

42 Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley Figure 2-21f Box trace of solveTowers(3,'A', 'B', 'C')


Download ppt "Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley CHAPTER 2 Recursion:"

Similar presentations


Ads by Google