Verified Multiple Choice and Conceptual Actual 100% Correct Detailed Answers
Guaranteed Pass!!Current Update!!
*Ω* / Big Omega - lower bound
-Printing an array is Ω(n), Ω(lgn), and Ω(1)
*O* => upper bound (oh)
-Printing an array is O(n), O(n^2), O(2^n)
Ω, O, Θ - Complexity *Θ* / Big Theta => both O and Ω - a tight bound on
runtime
-Industry meaning of big O is closer to what academics
mean by Θ. In interviews we always try to otter a tightest
description of runtime.
The number of digits (d) in a number (n) is on the order
of 10^d
d|n
2 | 1 to 10 (10^1)
3 | 1 to 100 (10^2
Complexity - number of digits (d) in a number (n)
n = 10^d
lgn = lg(10^d)
lgn = d
ctci
https://stackoverflow.com/questions/50261364/ex-
plain-why-time-complexity-for-summing-digits-in-a-num-
ber-of-length-n-is-ologn
Complexity - sort each string in a list, then sort the list itself
, Python Data Structures / Algorithms Frequently Tested Exam Questions With
Verified Multiple Choice and Conceptual Actual 100% Correct Detailed Answers
Guaranteed Pass!!Current Update!!
['aba', 'cbd', 'cdc'] ===> ['aab', 'bcd', 'ccd']
-n = # elements in list
-s = longest string
1) sort each string in list:
n * slgs
2) sort the list itself
s * nlgn
( comparing each string takes O(s)
total = n*s(lgn + lgs)
, Python Data Structures / Algorithms Frequently Tested Exam Questions With
Verified Multiple Choice and Conceptual Actual 100% Correct Detailed Answers
Guaranteed Pass!!Current Update!!
-many people think it's O(n * 2^n) - but in each call to
fib(n) , n is changing, so the total work is:
fib(1) => 2^1 steps
fib(2) => 2^2 steps
etc...
2^1 + 2^2 + 2^3 +. + 2^n ==> 2^N
Complexity - Computing first n fibonacci numbers O(2^N)
- The sum of powers 2^0 + 2^1 + 2^2 + 2^3 +. + 2^n
roughly equals 2^(n+1) - 1
recursive - 2^N / N
recursive memo - N/N
Complexity - Fibonacci and alternatives iterative - N/1
matrix mult - Lgn/1
formula - 1/1
, Python Data Structures / Algorithms Frequently Tested Exam Questions With
Verified Multiple Choice and Conceptual Actual 100% Correct Detailed Answers
Guaranteed Pass!!Current Update!!
append - O(1) (amortized)
pop - O(1)
insert and remove - O(n)
get item - O(1)
*in* membership testing - O(n)
-largest costs come from growing beyond the current
allocation size (because everything must move), or from
inserting or deleting somewhere near the beginning (be-
cause everything after that must move).
Python *List* Time Complexity -insertion and deletion messy (due to fixed sizes
-good for accessing elements in the middle
-If you need to add/remove at both ends, consider using
a collections.deque instead.
insert/delete - O(1)
Linked List Time Complexity *(removing last element w/ no tail can be O(n)