Big O Flashcards
What is Big O and why is it important
Big O time is the language and metric we use to describe the efficiency of algorithms. no knowing this concept can severely hurt you when developing an algorithm
O(N)
asymptotic runtime increases linearly with the amount of work to be done
O(1)
Time taken to complete a task, no matter how large it gets is constant.
Academic definition of big O
Big O describes an upper bound on the time it takes to complete a task. Think of it as “ the algorithm is at least as fast as x run time”
Academic definition of Big Omega
Big Omega is like Big O but for a lower bound on runtime. can be thought of as “ the algorithm wont be faster than x runtime”
Academic definition of Big Theta
Big Theta is both big O and big Omega. ie an algorithm is Theta(N) if it is both O(N) and Omega(N). Theta gives a tight bound on runtime.
Best case
The case that the algorithm runs that gives the lowest/ fastest runtime.
worst case
a case in which the algorithm takes the maximum amount of time it can to solve a problem.
Expected case
the run time that an algorithm usually takes
Utility of the cases
Best case is rarely used. Usually, expected case and worse case are the same. if they are not, both need to be independently described
what is the relationship between best/worse/expected case and bigO/Theta/Omega?
Best/worse/expected cases describe the Big O time for particular inputs or scenarios
BigO/Omega /Thetadescribe the upper, lower and tight end bounds for runtime
Space Complexity
a measurement of the space required by an algorithm
Tips about space complexity
actually allocating space in memory effects complexity, but so do function calls where the function is placed on the stack. if the function is not placed on the stack, then it does not effect complexity
Drop the constants when using Big O
O(2N) becomes O(N),
Drop non-Dominant terms
always drop non dominant terms
O(N^2 + N ) becomes O(N^2)
O(N + logN) becomes O(N)