DEV Community

Cover image for Time complexity does not refer to the time taken by the machine to execute a particular code...!!!
Jayesh Dineshbhai Pansuriya
Jayesh Dineshbhai Pansuriya

Posted on

Time complexity does not refer to the time taken by the machine to execute a particular code...!!!

What is Time Complexity?
We can solve a problem using different logic and different codes. Time complexity basically helps to judge different codes and also helps to decide which code is better. In an interview, an interviewer generally judges a code by its time complexity.

Now, the term, time complexity, seems that it is referring to the time taken by a machine to execute a particular code.
But in real life, Time complexity does not refer to the time taken by the machine to execute a particular code.

Let’s understand why we should not judge any code on the basis of the time taken by a machine.

If we run the same code in a low-end machine(e.g. old windows machine) and in a high-end machine(e.g. Latest MacBook), we will observe that two different machines take different amounts of time for the same code. The high-end machine will take lesser time as compared to the low-end machine.

So, the time taken by a machine can be changed depending on the configuration. That is why we should not compare the two different codes on the basis of the time taken by a machine as the time is dependent on it.

Definition:
The rate at which the time, required to run a code, changes with respect to the input size, is considered the time complexity. Basically, the time complexity of a particular code depends on the given input size, not on the machine used to run the code.

Top comments (0)