Solution Manual for Data Abstraction & Problem Solving with Walls and Mirrors 6E 6th Edition.

Solution Manual for Data Abstraction & Problem Solving with Walls and Mirrors 6E 6th Edition.

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Data Abstraction and Problem Solving with C++: Walls and Mirrors , 6th edition, Frank M. Carrano and Timothy Henry. Solutions to Exercises, Ver. 6.0. 5 Chapter 2 Recursion: The Mirrors 1 The problem is defined in terms of a smaller problem of the same type: Here, the last value in the array is checked and then the remaining part of the array is passed to the function. Each recursive call diminishes the size of the problem: The recursive call to getNumberEqual subtracts 1 from the current value for n, passing this as the parameter n in the next call, effectively reducing the size of the unsearched remainder of the array by 1. An instance of the problem serves as the base case: Here, the case where the size of the array is 0 (i.e.: n 0) results in the return of the value 0: an array of size 0 can have no instances of the desiredValue. This terminates the recursion. As the problem size diminishes, the base case is reached: n is an integer and is decremented by 1 with each recursive call. After n recursive calls, the parameter n in the n th call will have the value 0 and the base case will be reached. 2a The call rabbit(5) produces the following box trace: Follow the rabbit(4) call Follow the rabbit(3) call Follow the rabbit(2) call Base case: n = 2 The rabbit(2) call completes n = 5 rabbit(4) = ? rabbit(3) = ? return ? n = 5 rabbit(4) = ? rabbit(3) = ? return ? n = 4 rabbit(3) = ? rabbit(2) = ? return ? n = 5 rabbit(4) = ? rabbit(3) = ? return ? n = 4 rabbit(3) = ? rabbit(2) = ? return ? n = 3 rabbit(2) = ? rabbit(1) = ? return ? n = 5 rabbit(4) = ? rabbit(3) = ? return ? n = 4 rabbit(3) = ? rabbit(2) = ? return ? n = 3 rabbit(2) = ? rabbit(1) = ? return ? n = 2 return 1 n = 5 rabbit(4) = ? rabbit(3) = ? return ? n = 4 rabbit(3) = ? rabbit(2) = ? return ? n = 3 rabbit(2) = ? rabbit(1) = ? return ? n = 2 return 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Data Abstraction and Problem Solving with C++: Walls and Mirrors , 6th edition, Frank M. Carrano and Timothy Henry. Solutions to Exercises, Ver. 6.0. 6 Follow the rabbit(1) call Base case: n = 1 The rabbit(1) call completes The rabbit(3) call completes Follow the rabbit(2) call Base case: n = 2 The rabbit(2) call completes The rabbit(4) call completes Follow the rabbit(3) call Follow the rabbit(2) call Base case: n = 2 The rabbit(2) call completes n = 5 rabbit(4) = ? rabbit(3) = a? return ? n = 4 rabbit(3) = ? rabbit(2) = ? return ? n = 3 rabbit(2) = 1 rabbit(1) = ? return ? n = 5 rabbit(4) = ? rabbit(3) = ? return ? n = 4 rabbit(3) = ? rabbit(2) = ? return ? n = 3 rabbit(2) = 1 rabbit(1) = ? return ? n = 1 return 1 n = 5 rabbit(4) = ? rabbit(3) = ? return ? n = 4 rabbit(3) = ? rabbit(2) = ? return ? n = 3 rabbit(2) = 1 rabbit(1) = 1 return 2 n = 1 return 1 n = 5 rabbit(4) = ? rabbit(3) = ? return ? n = 4 rabbit(3) = 2 rabbit(2) = ? return ? n = 3 rabbit(2) = 1 rabbit(1) = 1 return 2 n = 1 return 1 n = 5 rabbit(4) = ? rabbit(3) = ? return ? n = 4 rabbit(3) = 2 rabbit(2) = ? return ? n = 5 rabbit(4) = ? rabbit(3) = ? return ? n = 4 rabbit(3) = 2 rabbit(2) = ? return ? n = 2 return 1 n = 5 rabbit(4) = ? rabbit(3) = ? return ? n = 4 rabbit(3) = 2 rabbit(2) = 1 return 3 n = 2 return 1 n = 5 rabbit(4) = 3 rabbit(3) = ? return ? n = 4 rabbit(3) = 2 rabbit(2) = 1 return 3 n = 2 return 1 n = 5 rabbit(4) = 3 rabbit(3) = ?
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern