Question: Analyze each of the three algorithms in source code form. To analyze an algorithm by giving the upper bound in Big-Oh notation on the execution

Analyze each of the three algorithms in source code form.

To analyze an algorithm by giving the upper bound in "Big-Oh" notation on the execution time of the algorithm and briefly explain your reasoning.

// Algorithm #1

int Max_Subsequence_Sum( const int A[], const int N )

{

int This_Sum = 0, Max_Sum = 0;

for (int i=0; i

{

This_Sum = 0;

for (int j=i; j

{

This_Sum += A[j];

if (This_Sum > Max_Sum)

{

Max_Sum = This_Sum;

}

}

}

return Max_Sum;

}

************************************************************************************************ ********************************************************** **********************************************************

// Algorithm #2

int Max_Subsequence_Sum( const int A[], const int N )

{

int This_Sum = 0, Max_Sum = 0;

for (int i=0; i

{

for (int j=i; 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;

}

****************************************************************************************************************************************************************************************************************************

// 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

{

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;

}

please give a detailed answer.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!