Anúncio
Próximos SlideShares
Chapter 3: Simplification of Boolean Function
Carregando em ... 3
1 de 2
Anúncio

### Algorithm MaxsubFastest(A)- Input- An n-element array A of numbers- in.docx

1. 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
Anúncio