Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a list of prices, eg, pries-110-15 20 30 40 60,-8025 , we would like to find the largest consecutive numbers in this list. In

image text in transcribed
Given a list of prices, eg, pries-110-15 20 30 40 60,-8025 , we would like to find the largest consecutive numbers in this list. In this example, the maximum sum of be 65 (from the interval f20,30,-40,60. In class wo discussed a brute-force algorithm and a faster (n logn) a gorithm that usod the divide and conquer techn que. In theee following problems you will use a divide and conquer technique too, but the problem is formulated in a diferent way 6. (10 points) Define m(L.0 to be the maxdimum sum of consocutive numbers in L with the hard constraint that these aumbers mast inclode LG. For example, using the list prices above, mprices,0)-10, m(prices,) 5 (15 20, muricea, 3)-50, m(prices, 4)--10, and so on. must be included), m(prices, 2) def a(L, i): if len(L) 0: return Lto) else: # fill in your code here titua t)-1 Complete the definition of the funetion m by providing additional Python code in the fuaction above. Hint: we know that the numbers/interval must end at LI. There are only two possibilities where the interval starts. Firet, the best one that gives the max sam) can start at i (and end there). Or, second, it can start before i; in this case, interval that must laclude Lji-1], should belp in computing m(L,t). m(L,t-1), which is the max sum of an 7 (10 points) To solve the original problem, we obeerve that the isterval containing the max sum in the list L must rectly define m(L,). Use it to compute

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions