Data Structures Exam 1 - Big O Notation
Polynomial Time v Non-Polynomial Time
-If something runs in Polynomial time the Big O notation is n^x (e.g. n, n^2, n^3, etc.) -If something runs in Non-Polynomial time the Big O notation is NOT of the form n^x.
Deterministic vs. Non-Deterministic
-Polynomial time is deterministic -Non-Polynomial time is non-deterministic
0! = ?
1
True or False. If: f(n) = 3n^2 + 10 n log n Then O(n) = n log(n)
False
True or False. If: f(n) = n log n + n/2 Then O(n) = n
False
Order of O(n) functions (listed in increasing order with fastest/smallest first)
O(1): Constant O(lg n) O(n): Linear O(n lg n) O(n^2): quadratic O(n^3): cubic O(2^n): exponential O(n!): factorial
Big-O Notation of: f(n) = n^2+100n+log(n)+1000
O(f(n))=n^2
Big-O Notation of: for (i = 1; i < n; i++) { for (j = 1; j < n; j++) { //statements } }
O(n)=n^2
Finding Big-O of nested for/while loops (to n).
cn^x, where x is the number of loops and and c is the number of constant time operations contained within the innermost loop.
Big-O Notation of: for (i = sum = 0; i < n; i++) sum += a[i];
f(n)=2+2n O(f(n))=2n=n
Big-O Notation of: a = 1 b = 3 c = 3a
f(n)=3 O(n)=1
Big-O Notation of: for (i=0; i < n; i++) { for (j = 0; i < n; j++) { // statements } } for (k = 0; k < n; k++) { // statements }
f(n)=n^2+n O(n)=n^2