Advertisement

Upcoming SlideShare

Chapter 3: Simplification of Boolean Function

Loading in ... 3

Feb. 3, 2023•0 likes## 0 likes

•7 views## views

Be the first to like this

Show More

Total views

0

On Slideshare

0

From embeds

0

Number of embeds

0

Download to read offline

Report

Education

Algorithm MaxsubFastest(A): Input: An n-element array A of numbers, indexed from 1 to n. Output: The maximum subarray sum of array A. M0 0 // the initial prefix maximum for t 1 to n do Mt max{0, Mt1 + A[t]} m 0 // the maximum found so far for t 1 to n do m max{m, Mt} return m Modify the description of the MaxsubFastest algorithm so that, in addition to the value of the maximum subarray summation, it also outputs the indices j and k that identify the maximum subarray A[j : k]. Solution M0 0 // the initial prefix maximum for t 1 to n do Mt max{0, Mt1 + A[t]} m 0 // the maximum found so far //upto here we store the max sub array... //here in these instructions,, we are iterating to calculate total sum of new subset array m //So 0 is the start position.. and array m length-1 is the last index print( \"start index: 0\"); print(\"Closing index: \"+m.length-1); for t 1 to n do m max{m, Mt} return m .

wviolaFollow

Advertisement

- Algorithm MaxsubFastest(A): Input: An n-element array A of numbers, indexed from 1 to n. Output: The maximum subarray sum of array A. M0 0 // the initial prefix maximum for t 1 to n do Mt max{0, Mt1 + A[t]} m 0 // the maximum found so far for t 1 to n do m max{m, Mt} return m Modify the description of the MaxsubFastest algorithm so that, in addition to the value of the maximum subarray summation, it also outputs the indices j and k that identify the maximum subarray A[j : k]. Solution M0 0 // the initial prefix maximum for t 1 to n do Mt max{0, Mt1 + A[t]} m 0 // the maximum found so far //upto here we store the max sub array... //here in these instructions,, we are iterating to calculate total sum of new subset array m //So 0 is the start position.. and array m length-1 is the last index print( "start index: 0"); print("Closing index: "+m.length-1); for t 1 to n do m max{m, Mt} return m

Advertisement