View the step-by-step solution to:

Assignment # 01 Give detailed Time Complexity Analysis (in terms of N) of the following C++ codes in terms of Big-Oh notation and justify your...

Assignment # 01


Give detailed Time Complexity Analysis (in terms of N) of the following C++ codes in terms of Big-Oh notation and justify your answer;(Where N is the input size). Label the operations.

Code # 1 (5)

int i=1;
while(i<N)
{
for(int j=1; j<N; j *= 5)
{
for(int k=0;k<N;k++)
cout<<”Complexity Analysis”;
}
i=i*3;
}




Code # 2 (5)

int i=1000;
int S=N/2;
while(i>N)
{
for(int j=1; j<=N; j++)
{
for(int k=0;k<S;k++)
{
k++;
}
}
i--;
}

Code # 3 (5)

void Func1(int N)
{
const int MaxSize = 100;
int array[MaxSize][MaxSize], k, l;
for(int i=0; i<N; i++)
for(int j=0; j<N; j++)
array[i][j] = 0;
array[0][(N-1)/2] = 1;
int key = 2;
i = 0;
int j = (N-1)/2;
while(key <= N*N)
{
if(i <= 0)
k = N-1;
else
k = i-1;
if(j <= 0)
l = N-1;
else
l = j-1;
if(array[k][l])
i = (i+1)%N;
else
{
i = k;
j = l;
}
array[i][j] = key;
key++;
}
int str=0;
for(i=0; i<N; i++)
{
for(j=0; j<N; j++)
str++;
}
int Sum = 0;
for(i=0; i<N; i++)
{
Sum += array[0][i];
}
}
Code # 4 (5)

void func1(int N)
{
if(N<=1)
cout<<N<<endl;
else
{
int fn;
int fnm2 = 0;
int fnm1 = 1;

for(int i=2; i<=N; i++)
{
int j=10000;
while(j>N)
{
fn = fnm1 + fnm2;
fnm2 = fnm1;
fnm1 = fn;
j--;
}
}
}
}

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question