Algorithm Analysis
Assignment 1 Order the following functions by growth rate: N, √𝑁, N1.5, N2, Nlog N, N loglogN,
Nlog2N, Nlog(N2), 2/N, 2N,2N/2, 37, N2logN, N3. Indicate which functions grow at the same rate.
Assignment 2. Give an analysis of running time of each following code (Big-Oh)
[Link] = 0;
for (i =1; i<= N; i++)
Sum += i*i*i;
b. Sum = 0;
for (i =1; i<= N; i++)
for(j=0;j <= N*N; j++)
Sum ++;
c. Sum = 0;
for (i =1; i<= N; i++)
for(j=0;j <= i; j++)
Sum ++;
d. Sum = 0;
for (i =1; i<= N; i++)
for(j=0;j <= i*i; j++)
for(k=0;k <= j; k++)
Sum ++;
e. Sum = 0;
for (i =1; i<= N; i++)
for(j=0;j <= i*i; j++)
if ( j%i== 0 )
for(k=0;jk<=j; k++)
Sum ++;
f. i=1; s=1;
while( s<= N)
{ i++;
s+=i;
}
Assignment 3 What is the running time of the following recursive function (specified as a
function of the input value n)
a.
b.
c.
Assignment 4
a. Write a program to evaluate the function 𝐹(𝑋) = 𝑎 𝑋 . All 𝑎 are the number of an
array of N elements which we already knew. After that, calculate your running time?
b. If your running time is O(N2), please find an algorithm with linear complexity.
Assignment 5
a. Write a program to determine if a positive integer, N, is prime.
b. In terms of N, what is the worst-case running time of your program?