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_2

Step: 3

blur-text-image_3

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 Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions

Question

To what extent can ndings from qualitative research be generalized?

Answered: 1 week ago

Question

Relational Contexts in Organizations

Answered: 1 week ago