Lab 7.pdf - CSci 1133 Fall 2019 Lab Exercise 7 Recursion This lab exercise introduces you to a powerful problem solving method using functional

Lab 7.pdf - CSci 1133 Fall 2019 Lab Exercise 7 Recursion...

• Lab Report
• 7

This preview shows page 1 - 2 out of 7 pages.

CSci 1133, Fall 2019 Lab Exercise 7 Recursion This lab exercise introduces you to a powerful problem solving method using functional recursion. Recursion refers to an abstraction which is defined in terms of itself . Examples include mathematical abstractions such as Fibonacci series, Factorials, and Exponentials, and other abstractions such as the Towers of Hanoi puzzle, the Eight Queens problem, and Fractal Geometry. Many interesting and challenging computational problems that are difficult to solve in an iterative fashion are very simple and elegant to solve using recursive function calls. Following the methods discussed in class, you should begin to get a feel for "thinking recursively". Warm-up 1). Sum of a list Write a recursive function to determine the sum of a list of integers. The function declaration is: def sum_list( vals ): where vals is a list of integers. Both partners should be prepared to respond to the prompts below before getting checked off by the TA. It is recommended that you explain this problem to a TA before moving on to the second warm-up problem. a. First, describe the base case. [Hint: in what size list would it be easiest to find the sum? And what value would it be?] b. Next, describe the reduction step. [Hint: describe the original problem using a simple case in combination with some reduced form of the problem. If you had a function that could compute the sum of a list of 9 elements, how could you use it to make the task of computing the sum of 10 elements much easier? Can you generalize this to finding the sum of a list of n elements with a function that only works with lists of n-1 elements?] c. Describe why the reduction step will 1) solve the problem and 2) always move closer to the base case.

You've reached the end of your free preview.

Want to read all 7 pages?

• Spring '14

What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern