How to calculate the complexity of time and space of algorithms

How to calculate the spatial and temporal complexity of algorithms in java.

Is the total execution time [Using System.nanoTime ()] equal to the complexity of the time of any graphograph or function?

Example: Estimating the complexity of space and time of the nth number in Fibonacci series

+3
source share
4 answers

Time complexity is a theoretical indication of scalability on an idealized machine. (its algorithm, not the machine)

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

, , , .

+5

[Using System.nanoTime()] ?

. Big-O. - , . .

+2

, , . , .

, , , , 500 , , .

And that’s all you get. Come on, man.

+1
source

First, you must determine the basic operation of the algorithm. Place a counter to calculate how many times the main operation works until your algorithm completes. Try to designate this counter as n. In Fibonacci series, the main operation is addition (adding the last two elements gives you the following) To calculate the nth number, you need to add n-1. Thus, the complexity of the Fibonacci series is realized as O (n)

0
source

Source: https://habr.com/ru/post/1780412/


All Articles