-1

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

Clark
  • 27
  • 8
  • 3
    Possible 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 Answers1

-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