January 2018
Intermediate to advanced
332 pages
7h 36m
English
Let's now discuss one of the most common time complexities, the linear time. As one can guess, linear time complexity of a method indicates that the method takes linear time to execute:
for(var i = 0; i < N; i += c) { // O(1) operations}
This is a very basic for loop, within which we are performing some constant time operations. As the size of N increases, the number of the times the loop gets executed also increases.
As you can see, the value of i in each iteration is incremented by a constant, c, and not by 1. This is because it does not matter what the increments are, as long as they are linear.
In the first iteration, the value of i = 0; in the second iteration, the value of i = c, then its c + c = 2c in the third iteration, ...
Read now
Unlock full access