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 heavily uses the big O notation to indicate the time complexity for an operation. Feel free to skip this paragraph if you are already familiar with this notation. While this notation sounds really complicated, the concept is actually quite simple.
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)
would take n
steps to execute, where n
is generally the size 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.
The purpose of this system is to indicate the approximate performance of an operation; this is separate from code speed but it is still relevant. A piece of code that executes a single step 1000
times faster but needs O(2**n)
steps to execute will still be slower...