0% found this document useful (0 votes)
127 views19 pages

Complexity Theory: Selected Exercises With Solutions On

This document contains solutions to exercises on complexity theory from a course on the theory of computation. It is divided into three exercise sheets, each containing three exercises. The exercises involve analyzing the complexity of algorithms and showing languages are included in complexity classes like P. The author is Amir Semmo and it was extracted from homework assignments from the University of Potsdam in 2008.

Uploaded by

pmignot
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views19 pages

Complexity Theory: Selected Exercises With Solutions On

This document contains solutions to exercises on complexity theory from a course on the theory of computation. It is divided into three exercise sheets, each containing three exercises. The exercises involve analyzing the complexity of algorithms and showing languages are included in complexity classes like P. The author is Amir Semmo and it was extracted from homework assignments from the University of Potsdam in 2008.

Uploaded by

pmignot
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Selected exercises with solutions on

Complexity theory

in the field of the

Theory of computation

Amir Semmo

Extracted from former homeworks in the course "Theory of computation II", Summer
term 2008, University of Potsdam

October 6, 2008
Contents

Exercise Sheet 1 3
Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Exercise Sheet 2 8
Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Exercise Sheet 3 14
Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2
Exercise Sheet 1

Exercise 1
Specify if the following statements are correct. Justify your answers!

(a) n2 = O(n) (d) 2n = o(n2 )

(b) 3n = 2O(n) (e) n = o(log n)

(c) 22 = O(22 ) (f) 1 = o(1/n)


n n

(a) n2 = O(n)

We just have to show that: n2 ≤ c · n, for all n ≥ n0 (n0 > 0) and a c > 0.
We know:

n2 ≤ c · n ⇔ n ≤ c

By this we see, that the proposition cannot be true, because for every x c, there
will always exist a number n which is bigger than c.

(b) 3n = 2O(n)

This statement is true, because:

3n ≤ 2c·n | log
⇔ n · log(3) ≤ c · n · log(2) |:n
⇔ log(3) ≤ c · log(2)

3
Theory of computation II
Amir Semmo Exercise Sheet 1

and since we have eleminated n, we can say that this equation is alawys true for
any c > 0 we choose!

n n
(c) 22 = O(22 )

This statement is true, because for c = 1 we have:


n n n
22 ≤ c · 22 = 22

which is true for all n > n0 and n0 = 0.

(d) 2n = o(n2 )

We can show that this statement is also true, by having a look at the limit of:

lim 2·n2 = lim 2


=0
n→∞ n n→∞ n

Since the limit is 0, we showed that for any c > 0, the expression 2n is smaller than
c · n2 for all n ≥ n0 (n0 > 0).

(e) n = o(log n)

This statement is not true. We can show this again with the help of the limit:
n l0 Hospital
lim = lim 1 = lim n = ∞
n→∞ log(n) n→∞ 1/n n→∞

Since the limit is not 0, we have disproven the proposition.

(f ) 1 = o(1/n)

The last statement is not true (it is almost the same as the previous proposition):

lim 1 = lim n = ∞
n→∞ 1/n n→∞

4
Theory of computation II
Amir Semmo Exercise Sheet 1

Exercise 2
Show that P is closed under the star operation, that means: If L ∈ P , then
L∗ = {w | w = w1 · · · wn for n ∈ N and w1 , . . . , wn ∈ L} is also in P .

Note: The approach, enumerating all decompositions of a word, doesn't work, be-
cause there are 2n−1 possibilities for the decomposition of a word (with the length n)
into non-empty parts. Instead of that, think about how you can reduce the problem
of the containedness of a word w in L∗ to the containedness of parts of w in L∗

We construct a Turing Machine M , which decides L∗ :


TM M = "On input w = w1 · . . . · wn :

1. Initialize the set A = {0}.

2. Iterate for i = 1 to |w|:


3. Iterate for j = 0 to i − 1:
4. If j ∈ A and wj+1 · . . . · wi ∈ L: A = A ∪ {i}.

3. If |w| ∈ A: accept. Else reject."

The procedure of our Turing Machine M can be illustrated by the following example:

Let w = cpknf be the input for M , with the following rules:


• cp, k , nf ∈ L
• c, p , n , f ∈
/L
The outer loop runs on input w from i = 1 to 5, where initially A = {0}:
• i = 1 / j = 0: 0 ∈ A and c ∈
/L
• i = 2 / j = 0: 0 ∈ A and cp ∈ L, ⇒ A = {0, 2}
• i = 2 / j = 1: j ∈
/A
• i = 3 / j = 0: 0 ∈ A and cpk ∈
/L
• i = 3 / j = 1: 1 ∈
/A
• i = 3 / j = 2: 2 ∈ A and k ∈ L, ⇒ A = {0, 2, 3}

5
Theory of computation II
Amir Semmo Exercise Sheet 1

• ...

⇒ A = {0, 2, 3, 5}.

By this, the set A contains all indices, which indicate from which position part
words of w are contained in L, in our example: w1 · w2 , w3 and w4 · w5 .
We solve the question if a word w is in L∗ , by building w step by step, and recording
in a set A, if a partition is present on the basis of previous results (subproblems).
This is often adressed as 'dynamic programming ' in literature.

6
Theory of computation II
Amir Semmo Exercise Sheet 1

Exercise 3
Show that the language

ALLDF A = {hAi | A is a DF A and L(A) = Σ∗ }

is in P .

We construct a decider M for the language ALLDF A :


TM M = "On input hAi, where A is a DF A:

1. Unmark all states of A.

2. Initalize an empty state stack.

3. Mark the start state of A and push it on the stack.

4. Iterate, while there is no state left on the stack:


4.1 If there is a transition from the state on top of the stack to an unmarked
state, mark this state and push it on the stack. Else pop the top state from
the stack.

5. Run through all marked states and check if each of these states is an accepting
state. If at least one state is marked, but is not an accepting state: reject,
else: accept."

What we are actually doing here, is marking every state, which can be reached by a
valid sequence of conguations. This is done by the method of 'Depth-rst search'.
We can implement the algorithm for DFS (in our case step 3-4) in O(n). All other
steps are either constant operations (step 2) or also linear (step 1 and 5).
By this we have found an algorithm, implemented by the Turing Machine M ,
which is clearly polynomial in it's time complexity. M also recognizes ALLDF A ,
so ALLDF A has to be in P .

7
Exercise Sheet 2

Exercise 1
A cycle in a directed graph G is a nite sequence of vertices v1 , . . . , vn of G, where
v1 = vn and G contains an edge from vi to vi+1 for all i ∈ {1, . . . , n − 1}. Specify
an ecient algorithm, which decides if a graph contains a cycle. Explain why your
algorithm is correct and analyze its time complexity.

The following algorithm, implemented by the Turing Machine M , decides if a di-


rected graph contains a cycle (on the basis of 'Depth-rst search'):
TM M = "On input G = (V, E):

1. Check if G is a valid directed graph, where V contains all vertices and E


contains pairs of vertices of V .

2. Mark all vertices v ∈ V initially as white.

3. Initilalize empty stack S and a vertex pointer v .

4. Iterate, as long as there are no white vertices left:


4.1 Mark the rst white vertex as gray and let v point to this vertex.
4.2 Push the vertex v on S and mark it as active.
4.3 Search for an edge e = (v, u) (u ∈ V ), where e has not been visited yet. If
no such e exists: Pop v from the stack, mark it as black and if there is still
a vertex left on the stack, then mark it as active and continue with step
6 for the new vertex. Else if stack is empty: Continue with step 5 (new
loop).

8
Theory of computation II
Amir Semmo Exercise Sheet 2

4.4 Mark the edge e as visited and check if u is marked as gray. If this is the
case: accept. Else mark u as gray, set it as the new vertex v and continue
with step 5.2.

5. When reached this point: reject."

The main idea is marking all those vertices as gray, which can be reached by a
previosuly chosen start vertex. If there is a cycle, there will be the point where we
will encounter an already marked vertex. The stack helps to return to a previous
vertex, in order to check if there are still outgoing edges (the main principle of
'Depth-rst search').

The intent of the colors are:


• white : A vertex never has been visited before.
• gray : A vertex has already been visited in the current searching for a cycle.
• black : A vertex has been visited in a previous searching for a cycle (this
helps for the distinction of white vertices).
For the runtime analysis we can say that the rst three steps run at most in O(n).
The loop in step four will run through all vertices at least one time in the sub
steps. So this step also has to run in O(n). Step 4.3 also runs in O(n), because all
vertices will be marked as gray step by step. For this the overall loop in step four
is inuenced by this sub step 4.3, which results in the complexity of O(n) (note: all
other steps in the loop are insignicant, bcause they run in constant time ).
Consequently we can say, that the whole algorithm runs in O(n).

9
Theory of computation II
Amir Semmo Exercise Sheet 2

Exercise 2
Consider the following problem:

IN DEP EN DEN T −SET = {hG, ki | k ≥ 2 and G is a graph, whose set of vertices


V contains a subset C ⊆ V of k elements, such that no two arbitrary vertices from
C are linked by an edge.}

1. Proof that IN DEP EN DEN T − SET is in N P . In order to show this,


specify a polynomial-time verier for this set. What is a certicate for the
containedness of a pair hG, ki in IN DEP EN DEN T − SET ?

2. Specify a polynomial-time reduction from CLIQU E to IN DEP EN DEN T −


SET . Explain why you reduction can be computed in polynomial time.

Let W be the polynomial-time verier for IN DEP EN DEN T − SET :

TM W = "On input hhG, ki , N i:

1. Check if k ≥ 2 and k = |N |. If this is not the case: reject.

2. For each n ∈ N , do the following:


2.1 Run through all v ∈ V of G and check if v = n. If this is the case: Continue
with the next n. Else: reject.

3. For each pair (ei , ej ) ∈ E , do the following:


3.1 Check if ei and ej are no elements of N . If at least one of them are in N :
reject.

4. When reached this point: accept the input."

The certicate is the subset N of G, which mark the proof for the membership of
hG, ki in IN DEP EN DEN T − SET . N contains all those vertices in G, which
form a valid independent set. They can be encoded as a sequence of indices, point-
ing to the relevant vertices in VG .

10
Theory of computation II
Amir Semmo Exercise Sheet 2

It is also clear, that W runs in polynomial time. The rst step is linear, where w
just check for a well-formed input. The rst loop runs in O(n2 ), where we check if
N ⊆ V . The second loop in step 3 also runs in O(n2 ), because we run through all
edges of E (O(n)) and check for each edge if it is contained in E (O(n))).
By this W runs in polynomial time and is a valid verier for IN DEP EN DEN T −
SET , wtih the conclusion that IN DEP EN DEN T − SET ∈ N P .

For the second part we need to show that CLIQU E ≤P IN DEP EN DEN T −SET ,
or in other words:

hG, ki ∈ CLIQU E ⇔ p(hG, ki) = hG0 , k 0 i ∈ IN DEP EN DEN T − SET .

Let us dene a Turing Machine P , which calculates p:


TM P = "On input w:
1. Check if the input is well-formed, that means w = hG, ki. If this is not the
case: Return hG0 , 0i, where G0 represents an empty graph, and halt.

2. Set E 0 = E .

3. Iterate for i = 0 to |V |.
3.1 Iterate for j = 0 to |V |.
3.1.1 If (vi , vj ) ∈ E : Delete (vi , vj ) from E 0 . Else insert (vi , vj ) to E 0 .

4. Return hG0 , ki, where V 0 = V and E 0 as the new set for edges, and halt."
After the rst step of P , all edges are inserted to the structure E 0 which not have
been existed before in E , and all edges are removed, which are already in E . Thus
we gain via the new set E 0 the complement structure of E . Consequently we can
say, that:

hG, ki ∈ CLIQU E ⇒ hG0 , ki ∈ IN DEP EN DEN T − SET ,

because all k vertices are isolated in the CLIQUE of G0 .


Additionally we can say, that:

/ IN DEP EN DEN T − SET ,


/ CLIQU E ⇒ hG0 , ki ∈
hG, ki ∈

11
Theory of computation II
Amir Semmo Exercise Sheet 2

because if hG0 , ki ∈ IN DEP EN DEN T − SET we would have a k-Clique (note:


The conclusion above results of the contraposition ).

Finally P runs in O(n3 ), because the outer loop in step 3 will be executed exactly
n-times, the inner loop in step 3.1 n-times and step 3.1.1 runs in O(n), which results
in O(n3 ).
Alltogether P calculates p, which represents a valid polynomial time reduction from
CLIQU E to IN DEP EN DEN T − SET .

12
Theory of computation II
Amir Semmo Exercise Sheet 2

Exercise 3

For a class of languages C , the class co − C is dened as co − C = {L | L ∈ C}.


For this, the class of languages coN P contains all languages, whose complement is
in N P . Proof the following statement: If N P 6= coN P , then P 6= N P .

Let us assume that N P 6= coN P . By this we can conclude, that there mus exist a
language in N P , which is not in coN P , or in other words:

/ NP .
∃L ∈ N P : L ∈

But this would mean, that N P is not closed under the operation of complement.
Not it is well-known, that P is closed under the operation of complement. We can
conclude:

∀LP ∈ P : LP ∈ P .

Now it is also well-known that P ⊆ N P :

⇒ ∀LP ∈ P : LP ∈ N P and LP ∈ N P (since P is closed under complement).

But with this conclusion, P cannot be equal to N P , because we showed that


N P is not closed under the operation of complement under the assumption that
N P 6= coN P . If we would assume at this point that P = N P , this would clearly
stand in conict with the conclusion that every language in P and its complement
would be in N P , which would result to that N P would be closed under the opera-
tion of complement, a contradiction!

Consequently we showed: P 6= N P .

13
Exercise Sheet 3

Exercise 1
Show that N P and coN P are subsets of P SAT and if N P = P SAT , it would follow
that N P = coN P .
Note: P SAT is the set of languages, which can be decided in polynomial time by a
deterministic Turing Machine with an oracle SAT .

First we will show that N P ⊆ P SAT , which is just the same as we need to show
that:

∀L ∈ N P ⇒ L ∈ P SAT .

We assume that L ∈ N P . It is well-known that SAT is N P -complete, so we can


conclude:

∃p : L ≤p SAT and p is a polyonmial time function, which reduces L to SAT .

Now we construct a Turing Machine M SAT , which is in P SAT and decides L in


polynomial time:

TM M SAT = "On input w:


1. Construct p(w).

2. Ask the oracle SAT with the input p(w). If the oracle answers with 'yes':
accept. Else reject."

L(M SAT ) = L, because w ∈ L ⇔ p(w) ∈ SAT . Additionally step 1 and 2 run in


polynomial time, so L ∈ P SAT .

14
Theory of computation II
Amir Semmo Exercise Sheet 3

For the second part we need to show that coN P ⊆ P SAT , or in other words:

L ∈ N P ⇒ L ∈ P SAT .

This can be achieved via the construction of M SAT , where we just invert the answer
of the oracle. By this we can be sure that the new M SAT decides L (in polynomial
time).

For the third part we assume that N P = P SAT , where we need to show that
N P = coN P .
At rst we show that coN P ⊆ N P , where we can conclude directly from our as-
sumption N P = P SAT , that P SAT ⊆ N P . We showed in the previous part that
coN P ⊆ P SAT , which results in: coN P ⊆ N P .

We still need to show that N P ⊆ coN P .


The complexity class P is closed under the operation of complement, so is P SAT ,
because we can just reinterpretate (swap) the accept and reject states of the decider
for a language L. We can conclude:

L ∈ P SAT ⇒ L ∈ P SAT .

Now we can manage to show our statement by using the precondition that N P =
P SAT , because if this would be the case any language in P SAT would be in N P and
vice versa. For that N P also has to be closed under the operation of complement:

L ∈ NP ⇒ L ∈ NP ,

which is just the same as L ∈ N P ⇒ L ∈ coN P by the dention of coN P , or in


other words: N P ⊆ coN P .

Finally we showed the two directions: N P ⊆ coN P and coN P ⊆ N P , under the
precondition that N P = P SAT . We can conclude that N P = coN P , which is
exactly what we wanted to show.

15
Theory of computation II
Amir Semmo Exercise Sheet 3

Exercise 2
Proof the following statement: P is closed under nondeleting homomorphisms if
and only if P = N P .
Note: Consider the following language (which is abviously in P ): S = {xy | x ∈
{0, 1}∗ is the encoding of a Boolean formula Φ and y ∈ {t, f }∗ is the encoding of a
variable assignment, which satises the formula Φ }.

We have to show two directions. First we assume that P is closed under nondeleting
homomorphisms, and we need to show that P = N P .
For this we take the SAT problem, which is known to be N P -complete. That
means if we can show with the help of our assumption (P is closed under nondelet-
ing homomorphisms) that SAT ∈ P , we could conclude P = N P .

Let S = {xy | x ∈ {0, 1}∗ is the encoding of a Boolean formula Φ and y ∈ {t, f }∗ is
the encoding of a variable assignment, which fullils the formula Φ } and S is in P .
We construct a homomorphism h with the following rules:

h(t) = #,
h(f ) = # and
h(x) = x, for all x ∈ Σ \ {f, t}.

Now we dene a modied SAT as follows:

SAT 0 = {hΦi #k | Φ is a satisable Boolean formula with k dierent literals}.

Obviously we can say: h(S) = SAT 0 , because we just convert the t and f symbols
of S to the number sign (#). By this we can also say that SAT 0 is in P , because
S is in P and by our asumption that P is closed under nondeleting homomorphisms.

In the last step we can "redene" SAT with the help of our new language SAT 0 .
Let M be a Turing Machine which decides SAT :

TM M = "On input hΦi:

16
Theory of computation II
Amir Semmo Exercise Sheet 3

1. For each unique literal in Φ, add a # symbol to the end of the input on the
tape.

2. Simulate the decider for SAT 0 (remember: SAT 0 is in P and for this a poly-
nomial time decider exists ) with the tape content as input and accept if the
decider accepts or reject respectively."

The rst step of M runs in polynomial time, as well as the second step, because we
just simulate the polynomial time decider for SAT 0 . Therefore M is a polynomial
time decider for SAT and we can conclude:

P = NP ,

because SAT is N P -complete!

The other direction, where we assume that P = N P , is very easy to show, as soon as
someone knows that N P is closed under nondeleting homomorphisms. From these
two statements it directly follows that P also has to be closed under nondeleting
homomorphisms.

17
Theory of computation II
Amir Semmo Exercise Sheet 3

Exercise 3
Let U N ARY −SU BSET −SU M be a variant of the "Subset-Sum" problem, where
all numbers are encoded unary. So if hx1 , . . . , xn iu = 0x1 1 . . . 10xn is the unary
encoding of the series x1 , . . . , xn , then we have: hS, tiu ∈ U N ARY − SU BSET −
SU M if and only if hS, ti ∈ SU BSET − SU M .

1. For the SU BSET − SU M problem it is well-known that there exists a poly-


nomial time reduction from 3SAT to SU BSET − SU M , where the reduc-
tion converts a Boolean formula Φ with the variables x1 , . . . , xn and clauses
c1 , . . . , ck to an instance of the SU BSET − SU M problem hS, ti, wherein the
elements of S and the number t are the rows of a table (note: see chapter 7.5
in M. Sipser's "Introduction to the Theory of Computation" ).
Please answer why this polynomial time reduction cannot be transferred to
the U N ARY − SU BSET − SU M problem.

2. Proof that U N ARY − SU BSET − SU M is in P .

The polynomial-time reduction for 3SAT to SU BSET − SU M maps words from


3SAT to SU BSET − SU M . The operative point why this cannot be transferred to
the U N ARY − SU BSET − SU M (U SS ) problem is the encoding of the numbers
of the input.
The complexity of the mapping function f depends on the length of the input,
which is encoded binary as we relate it to 3SAT .
Let us dene the length of the input with n. In order to achieve a transformation to
an unary encoding, the length would increase exponentially to 2n (except for that
the output is logarithmic in n, but this cannot be the case regarding the construc-
tion of f ). So alltogether this would result for the total amount of steps, which need
to be processed by the mapping function f , to an exponentially dimension regarding
the mapping to the unary range of numbers. For this reason the reduction would
could not be achieved in polynomial time.

18
Theory of computation II
Amir Semmo Exercise Sheet 3

For the second part we need to show that U SS is in P . This time we won't show
this via detailed reductions to other problems in P , but rather via argumentation.
We could construct a Turing Machine M , which processes the following two steps:

1. Converting the unary input to a binary input (numbers).

2. To simulate the non-deterministic Turing Machine N for the SU BSET −


SU M problem by running it on the previously converted input, where we
accept if N accepts and reject if N rejects.

The rst step runs in polynomial time. The input w has the length of n, but because
of the rst step we reduce this length to log(n).
Now we know that M is a deterministic Turing Machine which just simulates an-
other non-deterministic Turing Machine in the second step. A theorem declares
that every t(n) time nondeterministic single-tape Turing Machine has an equiv-
alent 2O(t(n)) time deterministic single-tape Turing Machine. By this we can say
that the secnod step of our Turing Machine M , where we just behave like the non-
deterministic Turing Machine N , runs in 2O(n) .
Now our input has been reduced to the complexity of O(log(n)) after M nished
the rst step. For that we can say that the exponential dimension for the second
step is compensated by the logarithmic dimension of the rst step, which has to
result in a polynomial overall runtime of M .
For that M is polynomial-time decider for U SS and U N ARY − SU BSET − SU M
is in P .

19

You might also like