Access over 35 million academic & study documents

4 1 2 intoduction to algorithms Write pseudocode for the brute force

Content type
User Generated
Showing Page:
1/2
4.1-2 intoduction to algorithms Write pseudocode for the
brute-force method of solving the maximum-subarray
problem. Your procedure should run in G (n2 time.
Solution
FIND-MAX-SUBARRAY(A, low, high)
left = 0
right = 0
sum = -
for i = low to high
current-sum = 0
for j = i to high
current-sum += A[j]
if sum < current-sum
sum = current-sum
left = i
right = j
return (left, right, sum)

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/2

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
4.1-2 intoduction to algorithms Write pseudocode for the brute-force method of solving the maximum -subarray problem. Your procedure should run in G (n2 time. Solution FIND-MAX-SUBARRAY(A, low, high) left = 0 right = 0 sum = for i = low to high current-sum = 0 for j = i to high current-sum += A[j] if sum < current-sum sum = current-sum left = i right = j return (left, right, sum) Name: Description: ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4