DSA - MATHS & COMPLEXITY Flashcards
What is the time complexity for a loop?
O(n)
What is the time complexity for a nested loop?
O(n^2)
What is worst case for Linear search
O(n)
Why is Maths Good for Complexity Analysis?
Needs to check whether the choice ADTs is correct one for the chosen for the task or program
What Does 2^10 equal? & Why is it useful?
-1024
- Useful when calculating greater powers like 2^50
Define Log;
log_a(b) is the number you have to raise a to in order to get to b
What are the 2 Dimensions we might be interested in?
TIME & SPACE
What is TIME Performance?
How Long the algorithm takes to run?
Measure it in the number of Steps, due to normal time units depend on machine its on
What is SPACE Performance?
How much memory it requires?
Different algorithms to accomplish the same task may use different amounts of memory.
Define Big O:
f(n) = O(g(n))
=> g is an upper bound on how fast f grows as n increases
=> Only refer to relative growth.
How fast f grows in respect to how fast g grows
==> |f(n)| ≤ |Cg(n)|
where C is constant and n> n_0
Define little o:
f(n) = o(g(n))
=> A Stricter Upper Bound than BIG O
Define Theta:
f(n) = θ(g(n))
=> Provides both Upper bound and Lower bounds, which
are given as the same function but with different
constants
=> f & g grow at same rate
=> More precise than BIG O & little o
=> Tighter range of speeds for complexity
=> Bounded ABOVE but also BELOW x
==> C_1g(n) ≤ f(n) ≤ C_2g(n)
for positive constants of C_1, n_0& C_2, where n>n_0
=> f & g have the same rates of growth, with some constant
multiple
=> ONLY true if f(n) = O(g(n)) & g(n) = O(f(n))
Define Asymptotically Equal:
f(n) ~ g(n)
=> Stricter Upper and Lower Bounds
=> f’(n) = g’(n)
=> One grows faster the other would grow to 0 or ∞
Define Omega:
f(n)= Ω(g(n))
=> a Lower bound on how fast f grown as n increases
=> ONLY Lower bound of θ
=> Lower bound equivalent Big O
=> As f grows it will always grow at least at same rate as g
and CAN grow Faster
==> |f(n)|≥ |Cg(n)|
for a +ve C, n_0, where n>n_0
Average Case Complexity:
Average complexity overall all possible inputs