Big O Notation Flashcards
Define Big O Notation
Metric used to measure how efficient an algorithm is. How an algorithm scales with input
Expected Case
Usually the runtime that occurs on a daily basis
Worst Case
The unlucky case, usually runs the worst or is least performant
Best Case
The lucky case, usually runs the fastest
Dropping non dominant term
Getting rid of all terms smaller than the largest big O value. Constants can also be dropped
Space complexity
Big O can also be used to describe space complexity. This is usually to describe how much space is needed for a data structure IN the algorithm.
What is the big O of two for loops that aren’t nested and iterate through the same array length n?
2n, but you can drop the terms. This would run in linear time or O(n)
What is the big O of two for loops that are nested and iterate through the same array length n?
Since for each value of the first loop has to wait for a whole iteration of the second, the loop would run in O(n^2)