Answered step by step
Verified Expert Solution
Question
1 Approved Answer
find the time and space complexity of the following piece of java code: public static int [ ] findMaximumSubarray ( Vector A , int low,
find the time and space complexity of the following piece of java code:
public static int findMaximumSubarrayVector A int low, int high
if high low
return new intlow high, Agetlow;
else
int mid low high;
int left findMaximumSubarrayA low, mid;
int right findMaximumSubarrayA mid high;
int cross findMaxCrossingSubarrayA low, mid, high;
if left right && left cross
return left;
else if right left && right cross
return right;
else
return cross;
public static int findMaxCrossingSubarrayVector A int low, int mid, int high
int leftSum Integer.MINVALUE;
int sum ;
int maxLeft ;
for int i mid; i low; i
sum sum Ageti;
if sum leftSum
leftSum sum;
maxLeft i;
int rightSum Integer.MINVALUE;
sum ;
int maxRight ;
for int j mid ; j high; j
sum sum Agetj;
if sum rightSum
rightSum sum;
maxRight j;
return new intmaxLeft maxRight, leftSum rightSum;
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