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

Week-2

Week-2

by Arif Hosen -
Number of replies: 0

Answer to the Question No. 01

The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. A lot of times, there is more than one way to solve a particular problem and we should be able to identify the most efficient solution out of all. This is where time complexity comes into the picture. Time complexity helps us compare the performance of different solutions, thus helping us determine the most efficient solution. This is why we need to know time complexity.

 

Answer to the Question No. 02

This code contains bug.
These are,
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³) [ lower power finish ]

The time complexity is n³.