Question: FindMaxSubarraySum ( A , low, high ) if high = = low then return A [ low ] end if mid = ( low +
FindMaxSubarraySumA low, high if high low then return Alow end if mid low high leftMaxSum FindMaxSubarraySumA low, mid rightMaxSum FindMaxSubarraySum crossMaxSum FindMaxCrossSubarraySumA low, mid, high ans max crossMaxSum return ans FindMaxCrossSubarraySumA low, mid, high maxSuffixSum suffixSum for i mid downto low do suffixSum suffixSum Ai if suffixSum maxSuffixSum then maxSuffixSum suffixSum end if end for maxPrefixSum prefixSum for i mid to high do prefixSum prefixSum if prefixSum maxPrefixSum then maxPrefixSum prefixSum end if end for crossMaxSum maxSuffixSum maxPrefixSum return crossMaxSum Analyze the running time Tn of the algorithm, you can assume n is a power of FindMaxSubarraySumA low, high if high low then return Alow end if mid low high leftMaxSum FindMaxSubarraySumA low, mid rightMaxSum FindMaxSubarraySum crossMaxSum FindMaxCrossSubarraySumA low, mid, high ans max crossMaxSum return ans FindMaxCrossSubarraySumA low, mid, high maxSuffixSum suffixSum for i mid downto low do suffixSum suffixSum Ai if suffixSum maxSuffixSum then maxSuffixSum suffixSum end if end for maxPrefixSum prefixSum for i mid to high do prefixSum prefixSum if prefixSum maxPrefixSum then maxPrefixSum prefixSum end if end for crossMaxSum maxSuffixSum maxPrefixSum return crossMaxSum Analyze the running time Tn of the algorithm, you can assume n is a power of to simply the analysis: Tn T n The total running time of this algorithm is in to simply the analysis: Tn T n The total running time of this algorithm is in
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
