Time complexity – The big O notation
Before we can begin with this chapter, there is a simple notation that you need to understand. This chapter uses the big O notation to indicate the time complexity for an operation. Feel free to skip this section if you are already familiar with this notation. While the notation sounds really complicated, the concept is actually quite simple.
The big O letter refers to the capital version of the Greek letter Omicron, which means small-o (micron o).
When we say that a function takes O(1)
time, it means that it generally only takes 1
step to execute. Similarly, a function with O(n)
time would take n
steps to execute, where n
is generally the size (or length) of the object. This time complexity is just a basic indication of what to expect when executing the code, as it is generally what matters most.
In addition to O, several other characters might pop up in literature. Here’s an overview of the characters...