The concept

The time complexity is used to see how long an algorithm will take for a given amount of data. To describe this complexity, computer scientists use the mathematical big O notation. This notation is used with a function that describes how many operations an algorithm needs for a given amount of input data.

For example, when I say “this algorithm is in O( some_function() )”, it means that for a certain amount of data the algorithm needs some_function(a_certain_amount_of_data) operations to do its job.

What’s important is not the amount of data but the way the number of operations increases when the amount of data increases. The time complexity doesn’t give the exact number of operations but a good idea.

In this figure, you can see the evolution of different types of complexities. I used a logarithmic scale to plot it. In other words, the number of data is quickly increasing from 1 to 1 billion. We can see that:

  • The O(1) or constant complexity stays constant (otherwise it wouldn’t be called constant complexity).
  • The O(log(n)) stays low even with billions of data.
  • The worst complexity is the O(n2) where the number of operations quickly explodes.
  • The two other complexities are quickly increasing.

results matching ""

    No results matching ""