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.
Asked
Active
Viewed 376 times
1
-
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" – vzn Feb 16 '14 at 02:10
1 Answers
5
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.

David Richerby
- 81,689
- 26
- 141
- 235
-
However, there might be an algorithm which works in many useful cases, for example when the functions are "primitive recursive" or with known complexity. – Yuval Filmus Feb 15 '14 at 05:02