Access over 20 million homework & study documents

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)

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.

Anonymous
Great! Studypool always delivers quality work.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Similar Documents