4 | Elementary operations / Asymptotics II Flashcards
Elementary operation?
- execution time can be bounded above by a constant depending on particular implementation.
- constant does not depend on size of instance
more:
- elementary operations take a unit cost!
- we only care about running time to within multiplicative constant, only parameter that matters is number of elementary operations
- Number of elementary operation IS NOT THE SAME AS Number of lines
Can multiplication be considered an elementary operation?
depends on size of numbers
Examples of elementary operations
additions
subtractions
multiplications
divisions
modulo operations
Boolean operations
comparisons
assignments
how does euclids algorithm achieve sublinear time complexity
This is because the size of the problem is effectively reduced by half in each recursive call, similar to the divide-and-conquer strategy seen in algorithms with logarithmic time complexity
~~~
function euclid(a, b):
if b is 0:
return a
else:
return euclid(b, a mod b)
~~~
Best algorithm for greatest common divisor of two numbers
Euclid
function gcdEuclid(π, π) (assuming π is the smaller) while π > 0 π‘ β π π β π πππ π π β π‘ return π
(vs
- use the definition - O(m)
- factorize into primes - factorization takes long time
Complexity: βin the order of [O(__)] β¦β meaning
We say that π(π) is in the order of f(π) [ O(f(π)) ] if π(π) is bounded from above by a positive real multiple of π(π) for a sufficiently large π.
π‘(π) β€ ππ(π) whenever π β₯ π0
β> Every instance of a given size π can be solved in time proportional to π (or less)
What is n0
The value of n for which the algorithm is overtaken by its upper bound
How to prove that f(n) is bound from above by g(n)?
What does this also mean?
there exists n0 and c such that for all n > n0, f(n) < cg(n)
f(n) is in the order of O(g(n))
O(g(n)) is the upper bound of f(n)
Maximum rule
π π π + π(π) = π(max(π π , π(π)))
Message: Focus only on the most dominant term
How to prove that a function t(n) is not in the order of another function f(n)
Use proof by contradiction!
Example.
π‘ π = 0.001π3, π π = 1000π2</sup
(can also use limit rule)
Limit rule:
lim π(π)
πββ π(π)
is in R+
β> ?
then π(π) β π(π π ) and π(π) β π(π π )
and
π(π) β Ξ(π(π))
Limit rule:
lim π(π)
πββ π(π)
= 0
β> ?
then π(π) β π(π π ) and π(π) β π(π π )
and
π(π) β π(π(π)) and π(π) β Ξ(π(π))
Limit rule:
lim π(π)
πββ π(π)
= β
β> ?
then π(π) β π(π π ) and π(π) β π(π π )
and
π(π) β Ξ©(π(π)) and π(π) β Ξ(π(π))
Lβhopitalβs rule
when to use?
lim π(π)
πββ π(π)
= 0/0 or Β±β/Β±β
Upper bound formal definition?
π(π(π))
βOmega of π(π)β
The set of all functions π‘(π) such that π‘ π β₯ cπ(π) , π β₯ π0, for c a positive real.
There exists an instance of a given size π that can be solved in time proportional to π(n)