Question: 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
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. Explain which is the most efficient algorithm.
// Algorithm #1
int Max_Subsequence_Sum( const int A[], const int N ) { int This_Sum = 0, Max_Sum = 0;
for (int i=0; i
// Algorithm #2
int Max_Subsequence_Sum( const int A[], const int N ) { int This_Sum = 0, Max_Sum = 0;
for (int i=0; i
// Algorithm #3
int Max_Subsequence_Sum( const int A[], const int N ) { int This_Sum = 0, Max_Sum = 0;
for (int Seq_End=0; Seq_End if (This_Sum > Max_Sum) { Max_Sum = This_Sum; } else if (This_Sum < 0) { This_Sum = 0; } } return Max_Sum; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
