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

Answers

Answers

by Sabrina Sultana -
Number of replies: 0

Answer no (1)

Time complexity is the total quantity of time needed by a code for its execution. By knowing time complexity, we can find out the more preferable code which is more time saver.

Answer no (2)

There are some errors in the code. They are-
1) The word "for" is missing in the 1st loop which is initialized by the "counter" variable.
2) Data type of "i" is not declared.
3) Semicolon(;) is missing in the last line "printf("hello")".

Time Complexity:
For the 1st loop time complexity = O(n)
Then, for the nested loop time complexity = O{(n^2)+1} =O(n^2)
And the for the last loop time complexity = log(n)
So, Time complexity of this code = O(n) + O(n^2) + log(n)
=O(n^2) (Answer)