Big O Notation
Topic | Source |
---|---|
๐ฅ๏ธ Tech | Cracking the Coding Interview |
The Big O notation is used to express the space or time complexity of an algorithm.
Imagine you have to send some data to a friend across the country. What would be the fastest way to send it over there? A digital file transfer? For small amounts of data this is certainly true, but for dozens of terabytes this might take days. In that case, driving or flying there and giving your friend a hard drive might be quicker. This is because digital file transfer takes longer the more data you send. Flying over there always takes the same amount of time. The time you need is linear.
The big O notation is the same. It gives you am idea how an algorithm will perform. Is the time needed linear, exponential or logarithmic? To express this, we write O(N) or O(Nยฒ), where N is the number of inputs, e.g. The length of an array.