What could be the best or easiest way for analyzing/solving time complexity of a program? Both for iterative and recursive methods. Thanks for your help
Asked
Active
Viewed 32 times
-1
-
3Possible duplicate of [How to find time complexity of an algorithm](http://stackoverflow.com/questions/11032015/how-to-find-time-complexity-of-an-algorithm) – Gary Apr 04 '17 at 03:51
-
This tread has some discussion about the topic of your question: [Big O, how do you calculate/approximate it?](http://stackoverflow.com/questions/3255/big-o-how-do-you-calculate-approximate-it) – Tutch Apr 04 '17 at 03:52
1 Answers
-1
Count how many times your basic operation will be executed.
For example:
int a = 0;
for (int i = 0; i < 5; i++){
a += 1;
}
your basic operation is a+=1
. so how many times will it be executed? for the example, 5
. Now instead of 5, we use n
. so how many times will your basic operation execute? n
times. then you can say the time complexity is O(n)
. This also goes for the recursive methods.

John Is No
- 144
- 8
-
-
you can mark the answer check if you think it is what you're looking for, or a vote up would be good. :) – John Is No Apr 04 '17 at 04:08