Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part c) Memoized Slice Sums. For this problem, first you need to write a recursive function slice-sum(lst, begin, end) that computes recursively the sum Ist[begin]
Part c) Memoized Slice Sums. For this problem, first you need to write a recursive function slice-sum(lst, begin, end) that computes recursively the sum Ist[begin] + Isr(begin +11-Ist[begin+21--Isrlend-1]. Parameter 1st ?s a list object or a tuple. This function returns exactly the same value as expression sum(lst[begin:endl). obget or uple his tundtion wtimas exaclys smregin ed The base case deals with an empty slice and the recursive case adds Ist[begin] to the slice_sum0 on the Your implementation of the slice_sum0 function must NOT use slices (e.g. Istli:j) in order to get any Write the function contract (including preconditions related to valid parameter range) in its docstring. The function must throw IndexError if the index parameters are invalid. Write a unit test function test slice_sum0 that uses testif0 to test function slice_sum0 for interesting cases, including the base case. Second, after the recursive version of slice_sum0 function works correctly, write a second version of this function that uses memoization to optimize it. Call the memoized function slice_sum m. This function caches function values returned for various values of parameters begin and end.. We can make the simplifying assumptions that over the execution time of the program the function slice_sum_m is called always with the same object referenced by parameter lst and that object never changes. (Otherwise it would make no sense to cache results!) Write a unit test function test_slice_m0 that uses testifO to test function s cases, including the base case. So, for part c)write in file pl py functions slice sum), test slice_ sumO, slice summO, and test slice sum m()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started