{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW3 - HW3 Recursion Due Friday at 11:59pm Assignment...

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

View Full Document Right Arrow Icon
HW3 Recursion Due: Friday, September 12, 2008 at 11:59pm Assignment Overview =================== This assignment serves to reinforce the recent lectures on recursion (also found in section 3.5 of the textbook). In this assignment you will trace a few recursive methods and then write some recursive methods of your own. Part 1: Tracing =============== You will be asked to trace two recursive methods using a variety of inputs. First though, we have provided an example (as well as an acceptable solution) so you know what we are looking for. A sample question might look as follows: int example(int arr[], int n) { if (n==0) return 0; else { int smallResult = example(arr, n - 1); return smallResult + arr[n-1]; } } Write the resulting trace, making sure to state what the value of returnValue will be once execution is complete. a. Assume that the call is as follows: int[] exArray = {1, 2, 3, 4}; int returnValue = example(exArray, 4); A solution for the above question might be as follows: example([1, 2, 3, 4], 4) smallResult = example([1, 2, 3, 4], 3) smallResult = example([1, 2, 3, 4], 2) smallResult = example([1, 2, 3, 4], 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
Image of page 2
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