You will analyze three algorithms to solve the maximum contiguous subsequence sum problem, and then evaluate the performance of instructor-supplied implementations of those three algorithms.  You will compare your theoretical results to your actual results in a written report. What is the maximum contiguous subsequence sum problem? Given a sequence of integers A1, A2, ..., An (where the integers may be positive or negative), find a subsequence Aj, ... , Ak that has the maximum value of all possible subsequences. The maximum contiguous subsequence sum is defined to be zero if all of the integers in the sequence are negative. Consider the sequence shown below.   A1:  -2   A2:  11   A3:  -4   A4:  13

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

You will analyze three algorithms to solve the maximum contiguous subsequence sum problem, and then evaluate the performance of instructor-supplied implementations of those three algorithms.  You will compare your theoretical results to your actual results in a written report.

What is the maximum contiguous subsequence sum problem?

Given a sequence of integers A1, A2, ..., An (where the integers may be positive or negative), find a subsequence Aj, ... , Ak that has the maximum value of all possible subsequences.

The maximum contiguous subsequence sum is defined to be zero if all of the integers in the sequence are negative.

Consider the sequence shown below.

  A1:  -2
  A2:  11
  A3:  -4
  A4:  13
  A5:  -5
  A6:   2

The maximum contiguous subsequence sum is 20, representing the contiguous subsequence in positions 2, 3, and 4 (i.e. 11 + (-4) + 13 = 20).  The sum of the values in all other contiguous subsequences is less than or equal to 20.

Consider a second sequence, shown below.

  A1:   1
  A2:  -3
  A3:   4
  A4:  -2
  A5:  -1
  A6:   6

The maximum contiguous subsequence sum is 7, representing the contiguous subsequence in positions 3, 4, 5, and 6 (i.e. 4 + (-2) + (-1) + 6 = 7).

Four different algorithms have been developed to solve this problem, you can download them below.

You will:

1. Analyze each of the three algorithms in source code form.
To analyze an algorithm, you will review the C++ source code, then give the upper bound (in "Big-Oh" notation) on the execution time of the algorithm and briefly explain your reasoning.

2. Compile and run the program to evaluate the performance of the three functions.
To evaluate the performance of an algorithm on a computer, you will call the functions in a driver (such as the one we supplied: proj9driver.cpp ) and execute the program.  The driver can call these three functions with different prototypes shown below.

int Max_Subsequence_Sum_BLUE (constint[], const unsigned int);int Max_Subsequence_Sum_GREEN(constint[], const unsigned int);int Max_Subsequence_Sum_RED (constint[], const unsigned int);

To evaluate a function, you will execute the program which uses that function for each of the following input sequence sizes:

      N = 64, 128, 256, 512, 1024, 2048

3. Write a report comparing your theoretical and actual results from 1. and 2.
        
In your report, include the times of all test cases for each combination of N and function (COLOR).

Your report will contain the following sections (in the order stated):

    a) analysis of Algorithm #1 (contained in "proj9algorithm1.cpp  download"-- this is the Blue function)
    b) analysis of Algorithm #2 (contained in "proj9algorithm2.cpp  download"-- this is the Green function)
    c) analysis of Algorithm #3 (contained in "proj9algorithm3.cpp  download"-- this is the Red function)
    d) the name and specification of the computer such as the Operating System, Processor, Memory.
    e) actual running times for function BLUE
    f) actual running times for function GREEN
    g) actual running times for function RED
    h) a statement about which algorithms from a) through c) are implemented by which functions (e) through (g) and conclusions about your theoretical and actual results
  
In sections (e) through (g), be sure to include the maximum contiguous subsequence sum for each array size to demonstrate that the computations are correct.

proj9algorithm1.cpp

// Algorithm #1

int Max_Subsequence_Sum( const int A[], const int N ) { int This_Sum = 0, Max_Sum = 0; for (int i = 0; i < N; i++) { This_Sum = 0; for (int j = i; j < N; j++) { This_Sum += A[j]; if (This_Sum > Max_Sum) { Max_Sum = This_Sum; } } } return Max_Sum;}

proj9algorithm2.cpp

// Algorithm #2int Max_Subsequence_Sum( const int A[], const int N ){ int This_Sum = 0, Max_Sum = 0; for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { This_Sum = 0; for (int k = i; k <= j; k++) { This_Sum += A[k]; } if (This_Sum > Max_Sum) { Max_Sum = This_Sum; } } } return Max_Sum;}

proj9algorithm3.cpp

// Algorithm #3int Max_Subsequence_Sum( const int A[], const int N ){ int This_Sum = 0, Max_Sum = 0; for (int Seq_End= 0; Seq_End < N; Seq_End++) { This_Sum += A[Seq_End]; if (This_Sum > Max_Sum) { Max_Sum = This_Sum; } else if (This_Sum < 0) { This_Sum = 0; } } return Max_Sum;}

include <iostream>
include <lomanip>
linclude <cstring>
linclude <cstdlib>
linclude "timer.h"
using namespace std;
int Max Subsequence_Sum_BLUE( const int A[J, const int N)
int This Sum = 0, Max Sum = 0;
for (int i = 0; i < N; i++)
This Sum
for (int j = i; j < N; j++)
This Sum +- A[j];
if (This Sum > Max Sum)
Max Sum=
This Sum;
return Max_Sum;
int main( )
int Size
int *Vec, Result[6];
char Answer;
Timer T[6];
64;
for (int i - 0; i < 6; i++)
Vec
= new Int [5ize];
srand( time(6) );
for (int j = e; j < Size; j++)
Vec[j] = rand() X 100 - 5e;
rand() X 100 - 50;
cout << "Do you wish Lo view the array contents? (Y or N): ";
cin >> Answer;
If (Answer
== Y | Answer ==
'y')
for (Int J = 0; j < Size; J++)
cout << Vec[] << "\n";
cout << endl;
T[1].start();
Result[1]
T[1].stop();
Max Subsequence Sum BLUE( Vec, Size );
Size = 2 Size;
for ( int 1 = 0; 1 < 6; 1++)
cout << "Maximum contiguous subsequence sum: " << Result [i] << "\n":
T[1].show();
cout << endl;
Transcribed Image Text:include <iostream> include <lomanip> linclude <cstring> linclude <cstdlib> linclude "timer.h" using namespace std; int Max Subsequence_Sum_BLUE( const int A[J, const int N) int This Sum = 0, Max Sum = 0; for (int i = 0; i < N; i++) This Sum for (int j = i; j < N; j++) This Sum +- A[j]; if (This Sum > Max Sum) Max Sum= This Sum; return Max_Sum; int main( ) int Size int *Vec, Result[6]; char Answer; Timer T[6]; 64; for (int i - 0; i < 6; i++) Vec = new Int [5ize]; srand( time(6) ); for (int j = e; j < Size; j++) Vec[j] = rand() X 100 - 5e; rand() X 100 - 50; cout << "Do you wish Lo view the array contents? (Y or N): "; cin >> Answer; If (Answer == Y | Answer == 'y') for (Int J = 0; j < Size; J++) cout << Vec[] << "\n"; cout << endl; T[1].start(); Result[1] T[1].stop(); Max Subsequence Sum BLUE( Vec, Size ); Size = 2 Size; for ( int 1 = 0; 1 < 6; 1++) cout << "Maximum contiguous subsequence sum: " << Result [i] << "\n": T[1].show(); cout << endl;
sampleoutput (1) - Notepad
File Edit Format
View Help
MSMacbookPro-2:a9 ms$ ./proj9
Do you wish to view the array contents? (Y or N): N
Do you wish to view the array contents? (Y or N): N
Do you wish to view the array contents? (Y or N): N
Do you wish to view the array contents? (Y or N): N
Do you wish to view the array contents? (Y or N): N
Do you wish to view the array contents? (Y or N): N
Maximum contiguous subsequence sum: 198
Process Timer
Elapsed Time
: 0.001s
Maximum contiguous subsequence sum: 295
Process Timer
Elapsed Time
: 0.001s
Maximum contiguous subsequence sum: 498
Process Timer
Elapsed Time
: 0.001s
Maximum contiguous subsequence sum: 673
Process Timer
Elapsed Time
:0.003304s
Maximum contiguous subsequence sum: 1108
Process Timer
Elapsed Time
: 0.009835s
Maximum contiguous subsequence sum: 1043
Process Timer
Elapsed Time
: 0.040073s
MSMacbookPro-2:a9 ms$
1.
Transcribed Image Text:sampleoutput (1) - Notepad File Edit Format View Help MSMacbookPro-2:a9 ms$ ./proj9 Do you wish to view the array contents? (Y or N): N Do you wish to view the array contents? (Y or N): N Do you wish to view the array contents? (Y or N): N Do you wish to view the array contents? (Y or N): N Do you wish to view the array contents? (Y or N): N Do you wish to view the array contents? (Y or N): N Maximum contiguous subsequence sum: 198 Process Timer Elapsed Time : 0.001s Maximum contiguous subsequence sum: 295 Process Timer Elapsed Time : 0.001s Maximum contiguous subsequence sum: 498 Process Timer Elapsed Time : 0.001s Maximum contiguous subsequence sum: 673 Process Timer Elapsed Time :0.003304s Maximum contiguous subsequence sum: 1108 Process Timer Elapsed Time : 0.009835s Maximum contiguous subsequence sum: 1043 Process Timer Elapsed Time : 0.040073s MSMacbookPro-2:a9 ms$ 1.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Problems on numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education