
Patrick B. answered 12/04/20
Math and computer tutor/teacher
for ( i = 1; i < n; i++ )
for ( j = 0; j < i; j++ )
typical of ORDER N^2
Wasif G.
asked 12/03/20(i) Consider the following code:
int myFunc(int A[], int n)
{
int i, j, max = 0;
int msis[n];
for ( i = 0; i < n; i++ )
msis[i] = A[i];
for ( i = 1; i < n; i++ )
for ( j = 0; j < i; j++ )
if (A[i] > A[j] &&
msis[i] < msis[j] + A[i])
msis[i] = msis[j] + A[i];
for ( i = 0; i < n; i++ )
if ( max < msis[i] )
max = msis[i];
return max;
}
a) What is the time complexity of the algorithm?
Patrick B. answered 12/04/20
Math and computer tutor/teacher
for ( i = 1; i < n; i++ )
for ( j = 0; j < i; j++ )
typical of ORDER N^2
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.