What is the fastest way of calculating Time Complexity of any code?

Specifically in Order of Growth(O).

2/2/2020 7:07:42 AM

Satyam R

1 Answer

New Answer


I don't think there is any "fastest" way. Calculating time complexity of an algorithm can get quite intricate and is not always easy to determine. In the end, it will depend on your experience and that will depend on practical exposure. So, with time, you will develop a sense for how to approach determination of time complexities. Other than that, for iterative algorithms, if simple enough, just count which lines get executed how many times. There is a lesson on determining runtime complexity this way on this app. For recursive algorithms, you have the master theorem; if not applicable you can use recursion trees or simply make a smart guess.