Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Time Complexity and Running time

What is the difference between time complexity and running time? Are they the same?

like image 244
Harshay Avatar asked Feb 06 '11 20:02

Harshay


2 Answers

Running time is how long it takes a program to run. Time complexity is a description of the asymptotic behavior of running time as input size tends to infinity.

You can say that the running time "is" O(n^2) or whatever, because that's the idiomatic way to describe complexity classes and big-O notation. In fact the running time is not a complexity class, it's either a duration, or a function which gives you the duration. "Being O(n^2)" is a mathematical property of that function, not a full characterisation of it. The exact running time might be 2036*n^2 + 17453*n + 18464 CPU cycles, or whatever. Not that you very often need to know it in that much detail, and anyway it might well depend on the actual input as well as the size of the input.

like image 136
Steve Jessop Avatar answered Oct 02 '22 21:10

Steve Jessop


The time complexity and running time are two different things altogether.

Time complexity is a complete theoretical concept related to algorithms, while running time is the time a code would take to run, not at all theoretical.

Two algorithms may have the same time complexity, say O(n^2), but one may take twice as much running time as the other one.

like image 28
akaHuman Avatar answered Oct 02 '22 23:10

akaHuman