Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in C that implements the algorithm on pp. 71 and 72 (shown below, from Introduction to Algorithms, 3rd Edition, by Cormen et

Write a program in C that implements the algorithm on pp. 71 and 72 (shown below, from Introduction to Algorithms, 3rd Edition, by Cormen et al) for solving the maximum subarray problem. Use as inputs three different arrays of size 16: one with all positive entries, and the other two with a mix of positive and negative entries. Submit the program, the inputs and the outputs. These are the only directions I have.

CODE ONE (From page 71) *****************************************************

image text in transcribed

CODE TWO (From page 72) **************************************************************

image text in transcribed

FIND-MAX-CROSSING-SUBARRAY (A, low, mid, high) 1 left-sum 2 sum -0 3 fori - mid downto low 4 5 if sum > left-sum - -oo sum - sum Ali] left-sum sum max-left i 7 8 right-sumoo 10 for j mid +1 to high 11sum-sum Alj] 12 if sum > right-sum 13 14 right-sum - sum max-right - j 15 return (max-left, max-right, left-sum +right-sum) FIND-MAXIMUM-SUBARRAY (A, low, high) 1 if highlow 2return (low, high, A[low]) 3 else mid - [(low + high)/2 4(lefi-low, left-high, left-sum) - 2 return (low, high, // base case: only one element FIND-MAXIMUM-SUBArRAY (A, low, mid) (right-low , right-high, right-sum) FIND-MAXIMUM-SUBARRAY (cross-low, cross-high, cross-sum) (A, mid 1,high) FIND-MAX-CROSSING-SUBARRAY (A, low, mid, high) 7 if left-sum right-sum and left-sum cross-sunm return (left-low, left-high, left-sum) 9 elseif right-sum > left-sum and right-sum 10 cross-sum return (right-low, right-high, right-sum) 11else return (cross-low, cross-high, cross-sum)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

Discuss the structure of social conversation. Give some examples.

Answered: 1 week ago