1/74
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Two key aspects of Analysis of Algorithms
Time analysis: How many instructions does the algorithm execute? 2. Space analysis: How much memory does the algorithm need to execute?
Sum of the first N integers (∑i)
\frac{N\left(N+1\right)}{2} . For large N, this is approximately \frac{N^2}{2} .
Sum of the first N terms of a geometric series (∑A^i)
\frac{A^{N-1}-1}{A-1}
Logarithm Definition: logX(B)=A
X^{A}=B
\log_{a}A+\log_{a}B
\frac{\log_{a}A}{\log_{a}B}
Logarithm Rule: loga(A^n)
n\log_{a}A
Logarithm Change of Base formula: logA(B)
\frac{\log_2B}{\log_2A}
Big-Oh Notation (f(n)=O(g(n)))
f(n) ≤ g(n). Upper bound (possibly equal). f(n) grows at a rate no faster than g(n).
Big-Oh cheat
f(n) = O(g(n)) == f(n) ≤ g(n)
Formal definition of Big-Oh (f(n)=O(g(n)))
There are positive constants c and n0 such that f(n) ≤ c⋅g(n) for all n ≥ n0
Big-Omega Notation (f(n)=Ω(g(n)))
f(n) ≥ g(n). Lower bound (possibly equal). f(n) grows at a rate no slower than g(n).
Big-Omega cheat
f(n) = Ω(g(n)) == f(n) ≥ g(n)
Formal definition of Big-Omega (f(n)=Ω(g(n)))
There is a constant c > 0 and an integer constant n0 ≥ 1 such that f(n) ≥ c⋅g(n) for n ≥ n0.
Big-Theta cheat
f(n) = Θ(g(n)) == f(n) = g(n)
Formal definition of Big-Theta (f(n)=Θ(g(n)))
There are constants c′>0 and c′′>0 and an integer constant n0≥1 such that c′⋅g(n) ≤ f(n) ≤ c′′⋅g(n) for n ≥ n0.
Little-oh cheat
f(n) = o(g(n)) == f(n) < g(n)
Limit definition for Little-oh (f(n) = o(g(n)))
limn→∞g(n)f(n) = 0.
Little-Omega cheat
f(n) = ω(g(n)) == f(n) > g(n)
Big-Oh Rule 1(Addition)
If T1(N)=O(f(N)) and T2(N)=O(g(N)), then T1(N)+T2(N)=max(O(f(N)),O(g(N))). (Drop lower-order terms).
Big-Oh Rule 2 (Multiplication)
If T1(N)=O(f(N)) and T2(N)=O(g(N)), then T1(N)⋅T2(N)=O(f(N)⋅g(N)).
Big-Oh Rule for Polynomials
If T(N) is a polynomial of degree k, then T(N)=Θ(Nk). (Drop lower-order terms and constant factors).
Time Complexity Rule 3: Consecutive Statements
Add them, and the complexity is the maximum of the individual running times.
Time Complexity Rule 4: If/Else
Running time = (running time of the test) + max(running time of S1, running time of S2).
Main Stack Operations
Push: Insertion. 2. Pop: Deletion (removes and returns top element). 3. Top (or peek): Returns top element without removing it.