Question
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
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