开发者

How to calculate time and space complexity of algorithms [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_如何学Python Closed 12 years ago.

How to calculate space and time complexity of algorithms in java.

Is the total time for execution [ Using System.nanoTime() ] equals time complexity of any alogrithm or function ?

Example : Space and Time Complexity estimate of nth number in fibonacci series


Time complexity is a theoretical indication of scalability on an idealised machine. (its about the algorithim, not the machine)

System.nanoTime() will tell you how long something took on a specific machine, in a specific state for specific data inputs.

Time complexity is better for working out worst case values, measuring is more useful if you have a specific use case you want to consider.


Is the total time for execution [ Using System.nanoTime() ] equals time complexity of any alogrithm or function ?

No. When calculating the complexity order of a program, it is usually done in the Big-O notation. Here is everything you need to know about it. With examples.


Firstly you must define basic operation of the algorithm. Put a counter to calculate how many times basic operation works till your algorithm finihed working. Try to denote this counter as n. In fibonacci series, basic operation is addition(adding last two elements give you the next) To calculate nth number, n-1 addition must be done. So, complexity of fibonacci series is realized as O(n)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜