Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the actual program in C++ Just 1 algorithm (number2) with the following specifications the array should contain negative and positive integers Write a program

Implement the actual program in C++ Just 1 algorithm (number2) with the following specifications the array should contain negative and positive integers

Write a program that solves Exercise 2.19. You need to modify the programs for each of the 4 algorithms for the maximum-subsequence-sum problem so that the program not only returns the maximum sums of subsequences of the given integer array but also returns/outputs the actual subsequence where the sum of integers is maximum. Run each algorithm on three randomly generated integer arrays of sizes N=1,000, 10,000, and 100,000, measure the running times, and determine if they are consistent with the theoretical analysis results of those algorithms given in class, i.e., if the running time of algorithm 1 for the MSS problem is proportional to N3 and that for Algorithm 2 is proportional to N2, etc. Include a table in your report that summarizes the actual running times (in appropriate time units) and narrative about your observations regarding whether the implemented algorithms indeed demonstrate behaviors entailed by theoretical analysis.

Exercise 2.19: The maximum contiguous subsequence sum algorithms in the text do not give any indication of the actual sequence. Modify them so that they return in a single object the value of the maximum subsequence and the indices of the actual sequence.

algorithm 3:

image text in transcribed:

2 Recursive maximum contiguous subsequence sum algorithm 3 Finds maximum sum in subarray spanning a[left..right]. 4* Does not attempt to maintain actual best sequence. 6 int maxSumRec const vector & a, int left, int right) if( left == right ) // Base case if a left1>0) 10 return al left ] else 12 return 0; int center ( left + right ) / 2; int maxLeftSummaxSumRec( a, left, center; int maxRightSum maxSumRec( a, center 1, right); 16 18 int maxLeftBorderSum-0, leftBorderSum: 0; for( int i = center; i >= left ;-i ) 20 leftBorderSum += a[ i ]; if( leftBorderSum> maxLeftBorderSum) maxLeftBorderSumleftBorderSum; int maxRightBorderSum 0, rightBorderSum: 0; for( int j = center + 1; J maxRightBorderSum) 29 30 maxRightBorderSum rightBorderSum; 32 return max3 maxLeftSum, maxRightSum, 35 maxLeftBorderSummaxRightBorderSum); 37 38 /** 9 Driver for divide-and-conquer maximum contiguous 40Subsequence sum algorithm. 41 42 int maxSubSum3( const vector & a ) return maxSumRec( a, 0, a.size( 1; Figure 2.7 Algorithm 3 2 Recursive maximum contiguous subsequence sum algorithm 3 Finds maximum sum in subarray spanning a[left..right]. 4* Does not attempt to maintain actual best sequence. 6 int maxSumRec const vector & a, int left, int right) if( left == right ) // Base case if a left1>0) 10 return al left ] else 12 return 0; int center ( left + right ) / 2; int maxLeftSummaxSumRec( a, left, center; int maxRightSum maxSumRec( a, center 1, right); 16 18 int maxLeftBorderSum-0, leftBorderSum: 0; for( int i = center; i >= left ;-i ) 20 leftBorderSum += a[ i ]; if( leftBorderSum> maxLeftBorderSum) maxLeftBorderSumleftBorderSum; int maxRightBorderSum 0, rightBorderSum: 0; for( int j = center + 1; J maxRightBorderSum) 29 30 maxRightBorderSum rightBorderSum; 32 return max3 maxLeftSum, maxRightSum, 35 maxLeftBorderSummaxRightBorderSum); 37 38 /** 9 Driver for divide-and-conquer maximum contiguous 40Subsequence sum algorithm. 41 42 int maxSubSum3( const vector & a ) return maxSumRec( a, 0, a.size( 1; Figure 2.7 Algorithm 3

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

Know when firms should not offer service guarantees.

Answered: 1 week ago

Question

Recognize the power of service guarantees.

Answered: 1 week ago