Discussion Forum on time complexity, self referential structure (Week 2)

D.F(week-2)

D.F(week-2)

by Fiaj Rahman(201-15-3077) -
Number of replies: 0

1) Ans:

The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.


2) Ans:


#include

int main() {


int counter, N;

printf("Enter a Positive Number\n");

scanf("%d", &N);

for(counter = 1; counter <= N; counter++) {


printf("%d \n", counter);}


int a=12,n=12;


if(N>10){


for(int i=0;i

for(i=0;i

a++; } }


for(int i=0;i

printf("hello");


}


}


return 0;


}


There are some bugs in this code.

In line 3: we have to declare i

In line 6: before counter we have to also put for

In line 14: we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)

Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .


Final result is = 0(n+1) + 0(n3) = 0 (n³)


The time complexity is n³.