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

Content type
User Generated
Rating
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)

Showing Page:
2/2

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.

### Review

Anonymous
Really useful study material!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4