4 | Elementary operations / Asymptotics II Flashcards

1
Q

Elementary operation?

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can multiplication be considered an elementary operation?

A

depends on size of numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Examples of elementary operations

A

additions
subtractions
multiplications
divisions
modulo operations
Boolean operations
comparisons
assignments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how does euclids algorithm achieve sublinear time complexity

A

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)
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Best algorithm for greatest common divisor of two numbers

A

Euclid

function gcdEuclid(π‘š, 𝑛) (assuming π‘š is the smaller)
    while π‘š > 0
        𝑑 ← π‘š
        π‘š ← 𝑛 π‘šπ‘œπ‘‘ π‘š
        𝑛 ← 𝑑
    return 𝑛

(vs
- use the definition - O(m)
- factorize into primes - factorization takes long time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Complexity: β€˜in the order of [O(__)] …’ meaning

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is n0

A

The value of n for which the algorithm is overtaken by its upper bound

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to prove that f(n) is bound from above by g(n)?

What does this also mean?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Maximum rule

A

𝑂 𝑓 𝑛 + 𝑔(𝑛) = 𝑂(max(𝑓 𝑛 , 𝑔(𝑛)))

Message: Focus only on the most dominant term

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to prove that a function t(n) is not in the order of another function f(n)

A

Use proof by contradiction!

Example.
𝑑 𝑛 = 0.001𝑛3, 𝑓 𝑛 = 1000𝑛2</sup

(can also use limit rule)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Limit rule:

lim 𝑓(𝑛)
π‘›β†’βˆž 𝑔(𝑛)

is in R+

–> ?

A

then 𝑓(𝑛) ∈ 𝑂(𝑔 𝑛 ) and 𝑔(𝑛) ∈ 𝑂(𝑓 𝑛 )

and

𝑓(𝑛) ∈ Θ(𝑔(𝑛))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Limit rule:

lim 𝑓(𝑛)
π‘›β†’βˆž 𝑔(𝑛)

= 0

–> ?

A

then 𝑓(𝑛) ∈ 𝑂(𝑔 𝑛 ) and 𝑔(𝑛) βˆ‰ 𝑂(𝑓 𝑛 )

and

𝑓(𝑛) ∈ 𝑂(𝑔(𝑛)) and 𝑓(𝑛) βˆ‰ Θ(𝑔(𝑛))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Limit rule:

lim 𝑓(𝑛)
π‘›β†’βˆž 𝑔(𝑛)

= ∞

–> ?

A

then 𝑓(𝑛) βˆ‰ 𝑂(𝑔 𝑛 ) and 𝑔(𝑛) ∈ 𝑂(𝑓 𝑛 )

and

𝑓(𝑛) ∈ Ξ©(𝑔(𝑛)) and 𝑓(𝑛) βˆ‰ Θ(𝑔(𝑛))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

L’hopital’s rule

when to use?

A

lim 𝑓(𝑛)
π‘›β†’βˆž 𝑔(𝑛)

= 0/0 or ±∞/±∞

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Upper bound formal definition?

A

𝛀(𝑓(𝑛))

β€ž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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Duality rule?

A

𝑑(𝑛) ∈ 𝛺(𝑓 𝑛 ) if and only if f 𝑛 ∈ 𝑂(𝑑(𝑛))

17
Q

Average case complexity

A

𝛩(𝑓(𝑛)) = 𝛺(𝑓(𝑛)) ∩ 𝑂(𝑓(𝑛))

The set of all functions 𝑑(𝑛) such that 𝑑𝑓(𝑛) ≀ 𝑑(𝑛) ≀
𝑐𝑓(𝑛) , 𝑛 β‰₯ 𝑛0 for 𝑐, 𝑑 positive reals.