Big-O Notation is a way of roughly measuring the performance of Algorithms.
Big-O is a mathematical notation that we borrowed in computer science toclassify algorithms by how they respond to the number (N) of items that you give them.
There are two primary things that you measure with Big-O:
- Time complexity refers to the total count of operations an algorithmwill perform given a set of items.
- Space complexity refers to the total memory an algorithm will take up while running given a set of items.
We measure these independently from one another because while an algorithm may perform fewer operations than another, it may also take up way more memory. Depending on what your requirements are, one may be a better choice than the other.
Some Common Big-O’s:
| Name | Notation | How you feel when they show up at your party |
|---|---|---|
| Constant | O(1) | AWESOME!! |
| Logarithmic | O(log N) | GREAT! |
| Linear | O(N) | OKAY. |
| Linearithmic | O(N log N) | UGH… |
| Polynomial | O(N ^ 2) | SHITTY |
| Exponential | O(2 ^ N) | HORRIBLE |
| Factorial | O(N!) | WTF |
