Big 0 Cheat Sheet



Big O Notation helps us determine how complex an operation is. It's of particular interest to the field of Computer Science. So for all you CS geeks out there here's a recap on the subject!

Big

When you start delving into algorithms and data structures you quickly come across Big O Notation. It tells us how long an operation will take to run, as the size of the data set increases.

The average case complexity describes the expected performance of the algorithm. Sometimes involves calculating the probability of each scenarios. It can get complicated to go into the details and therefore not discussed in this article. Below is a cheat-sheet on the time and space complexity of typical algorithms. Big O Cheatsheet for Common.

It's also a measure of complexity. The simple fact is that if something takes longer to run it is obviously more complex... logical eh? :)

Big O Notation

Here's a list of the more common Big O Notations from fastest (best) to slowest (worst).

  1. We can show that T(N) is O(N 2) by choosing c = 4 and n 0 = 2. This is because for all values of N greater than 2: 3. N 2 + 5 0 you choose, I can always find a value of N greater than n 0 so that 3. N 2 + 5 is greater than c. N. How to Determine Complexities.
  2. Then the total runtime of the algorithm is O(1 + N + 1).You can use algebra rules inside of Big O Notation, so final algorithm’s performance is O(N + 2). If an algorithm takes O(f(N.

Big O Cheat Sheet Poster Pdf

Notation Description
O(1)Constant: operations occur at the same speed no matter the size of the data set.

ie. doing a null check

O(log n)Logarithmic: operations take slightly longer as the size of the data set increases in orders of magnitude. Very close to O(1).

ie. finding an item in a sorted data set using a binary search

O(n)Linear: operations take longer in direct proportion to the size of the data set.

ie. adding up all the values in data set

O(n log n)Linearithmic: as the data set doubles in size, operations take longer by an increasing multiplier of one.

ie. a quick sort

O(n2)Quadratic: as the data set doubles in size, operations take four times longer.

ie. two nested loops over a data set

O(2n)Exponential: for every new element added to the data set operations take twice as long.

ie. brute force attacking a password

O(n!)Factorial: operations take n! times longer in direct proportion to the size of the data set.

ie. calculating fibonacci numbers recursively

They say a picture is worth a thousand words so this should help greatly with your understanding of the above :)

Big-o Cheat Sheet Poster Amazon

Conclusion

The key take away here is that if you are working with large data sets you need to be very careful when selecting the data structure and/or algorithm you use.

Big 0 Notation Cheat Sheet

I'm going to be starting a new series on Data Structures soon which will reference these Big O notations. That'll help show the real world application of these theoretical concepts.

Big-o Cheat Sheet Poster

Until then... happy coding!