Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ANSWER IN JAVA Implement both the Brute Force and Improved versions of the MCS algorithms. psuedocode for brute force Input: A sequence a1, a2, a3,

ANSWER IN JAVA

Implement both the Brute Force and Improved versions of the MCS algorithms.

psuedocode for brute force

Input: A sequence a1, a2, a3, ..., an-1, An.

Output: value, start and end of MCS.

Set maxSum < 0

for i= 1 to n do

Set sum <- 0

forj= i to n do

sum <--sum + a,

if (sum > maxSum).

maxSum <- sum

start <-- i

end <--j

Print start, end, maxSum and STOP.

psuedocode for Improved version

Algorithm MCSImproved

Set i <-- 1; Set start<-- end <-- 1

Set maxSum < sum < 0

for j= 1 to n do

sum <-- sum + a;

if (sum > maxSum)

maxSum -- sum

start <-- i

end <-- j

if (sum < 0)

i<-- j+1

sum <-- 0

Print start, end, maxSum and STOP

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

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions