Rasmus - Tutorial 9

advertisement
TUTORIAL 9
EXERCISE 1 (COMPULSORY)
Which of these definitions of the O-notation are correct?
1.
1.
2.
3.
f = O(g) iff, there exist positive integers c and n0 such that for all n ≥ n0 we have that f(n) ≥ c * g(n)
f = O(g) iff, for all positive integers c and n0 it is the case that for all n ≥ n0 we have that f(n) ≤ c * g(n)
f = O(g) iff, there exist positive integers c and n0 such that for all n ≥ n0 we have that f(n) ≤ c * g(n)
a. This is the correct, since there should EXIST a positive c and n0
4. f = O(g) iff, for all positive integers c and n0 it is the case that there exists an n ≥ n0 such that f(n) ≤ c * g(n)
EXERCISE 2 (COMPULSORY)
Which of the following claims are true? Give precise arguments (proofs) for your answers.
1.
2.
3.
4.
5.
6.
3𝑛2 + 2𝑛 + 7 = 𝑂(𝑛2 )
a. This is true for some positive integer c since 𝑛2 will always grow faster than n
2
𝑛 = 𝑂(𝑛 log 𝑛)
a. This is not true since 𝑛2 is growing a lot faster than 𝑛 log 𝑛 and will therefore dominate at some
point
3𝑛 = 2𝑂(𝑛) (hint: 3 = 2log2 3 )
a. True, since 2𝑂(𝑛) means an upper bound 𝑂(2𝑐𝑛 ) for some constant c
2
𝑛 = π‘œ(𝑛3 )
a. True, since it is the asymptotic upper bound
𝑛2 = π‘œ(𝑛2 )
a. False, since 𝑛2 will never be an asymptotic upper bound, but always equal
𝑛 = π‘œ(2𝑛)
a. True, since 2 n’s will always be bigger than 1
EXERCISE 3 (COMPULSORY)
Assume a 5-tape Turing machine M running in time𝑂(𝑛3 ). What is the time complexity of the corresponding singletape Turing machine simulating M.
Let 𝑑(𝑛) be a function where 𝑑(𝑛) ≥ 𝑛 then every 𝑑(𝑛) time multitape Turing machine has an equivalent 𝑂(𝑑 2 (𝑛))
time single-tape Turing machine.
The time complexity of the corresponding single-tape Turing machine is 𝑂(𝑑 2 (𝑛3 )).
EXERCISE 4 (COMPULSORY)
Which of the following statements about the class P are correct?
1.
2.
3.
4.
5.
P is the class of all languages that are decidable by deterministic single-tape Turing machines running in
polynomial time.
a. True
P is the class of all languages such that if 𝑀 ∈ 𝑃 then there is a deterministic single-tape Turing machine
which accepts the string w in polynomial time.
a. (True) depends if w belongs to P is true
P is the class of all languages that are decidable by deterministic multi-tape Turing machines running in
polynomial time.
a. True
A language L belongs to P iff there is a constant k and a decider M running in time 𝑂(π‘›π‘˜ ) such that 𝐿 = 𝐿(𝑀).
a. True
A language L belongs to P iff 𝐿 ∈ 𝑇𝐼𝑀𝐸(2𝑛 ).
a. False, since 2𝑛 is not polynomial time, lolzz
Give 5 languages that are in the class P. Does 𝐴 𝑇𝑀 belong to P?
𝐴 𝑇𝑀 does not belong to P since 𝐴 𝑇𝑀 is undecidable
1.
2.
3.
4.
5.
𝐿1 = {0π‘˜ 1π‘˜ | π‘˜ ≥ 0}
𝑃𝐴𝑇𝐻 = {⟨𝐺, 𝑠, 𝑑⟩| 𝐺 is a graph with a path from node s to t}
𝐸𝑉𝐸𝑁 = {π‘˜ | π‘˜ is an even number}
πΈπ‘„π‘ˆπ΄πΏ = {𝑀#𝑀 |𝑀 is {0,1}∗ }
𝑅𝐸𝐿𝑃𝑅𝐼𝑀𝐸 = {⟨π‘₯, 𝑦⟩|π‘₯ and 𝑦 are relatively prime} (RELPRIME = RELatively PRIME).
EXERCISE 5 (COMPULSORY)
Define the language 𝐴𝐿𝐿𝐷𝐹𝐴 and show that 𝐴𝐿𝐿𝐷𝐹𝐴 ∈ 𝑃
𝐴𝐿𝐿𝐷𝐹𝐴 = {⟨𝐷⟩| 𝐷 is a DFA and 𝐿(𝐷) = Σ ∗ }
M is a decider for 𝐴𝐿𝐿𝐷𝐹𝐴
M = “On input D:
1.
2.
3.
If the start state is not an accept state, reject. Else, mark it
O(1)
While there are still unmarked states connected to a marked state
O(n)
1. Go through all states connected to a marked state.
O(n)
1. If the state is not an accept state, reject. Else, mark it O(1)
Accept”
O(1)
𝑂(1 + 𝑛 ∗ 𝑛 ∗ 1 + 1) = 𝑂(𝑛2 )
𝐴𝐿𝐿𝐷𝐹𝐴 = O(𝑛2 )
𝐴𝐿𝐿𝐷𝐹𝐴 ∈ 𝑃
Download