This question already has an answer here:

I have Java function as input and want to get it's order for example O( n ) I search in the internet very hard but didn't find any thing can help me, is there any algorithms or package may help me.


marked as duplicate by Juho, Luke Mathieson, D.W., frafl, András Salamon Feb 17 '14 at 10:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ basically you look at the loops and nested loops. if you write out what its doing in pseudocode it would help. also so many std algorithms have known complexity eg sorting or whatever, it may just fit into an existing algorithm. so, "need more info" $\endgroup$ – vzn Feb 16 '14 at 2:10

No. There's no algorithm to analyze the asymptotic complexity of a piece of code given as input. Being able to do that would tell you whether the code halted and that's undecidable.

  • $\begingroup$ However, there might be an algorithm which works in many useful cases, for example when the functions are "primitive recursive" or with known complexity. $\endgroup$ – Yuval Filmus Feb 15 '14 at 5:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.