This preview shows pages 1–3. Sign up to view the full content.
CSIS0250B Design and Analysis of Algorithms
Sample Solution to Assignment Five
Questions 1  5 carry 20 marks each.
1. The input to the Clique3 problem consists of a graph
G
and a positive integer
b
where
the degree of
G
is bounded by 3. CLIQUE3 is the problem of determining whether
G
has a clique of size
b
. Note that the size of the biggest clique in
G
is at most 4 because
every vertex in
G
is adjacent to at most 3 other vertices.
(a) On input a graph
G
and a positive integer
b
,
Step 1:
return false if
b >
4;
Step 2:
guess a set
S
of
b
vertices in
G
;
Step 3:
return true if there is an edge in
G
between every pair of vertices in
S
.
Otherwise, return false.
Step 1 takes
O
(1) time, Step 2 takes
O
(
n
) time, while Step 3 takes
O
(
b
2
) =
O
(1)
time when
b
≤
4. So CLIQUE3
∈
NP.
(b) The direction of reduction is incorrect. To show that CLIQUE3 is NPcomplete,
one needs to prove CLIQUE
≤
P
CLIQUE3 instead.
(c) The reduction that says
C
is a vertex cover of
G
if and only if
V
−
C
is a clique
of
G
does not hold. Cosider a graph
G
with 4 vertices
{
a,b,c,d
}
and 3 edges
{
(
a,b
)
,
(
a,c
)
,
(
a,d
)
}
.
{
a
}
is a vertex cover of size 1, but
{
b,c,d
}
are not connected
and do not form a clique of size 3.
(d) The following procedure determines whether
G
has a clique of size
b
.
Step 1:
return false if
b >
4;
Step 2:
enumerate all subsets
S
of
b
vertices in
G
;
Step 3:
return true if there is an
S
that forms a clique of size
b
; otherwise, return
false.
There are
O
(

V

b
) subsets of
b
vertices in
G
. Checking whether
S
forms a clique of
size
b
takes
O
(
b
2
) =
O
(1) time for
b
≤
4. So the time taken by the algorithm is
O
(

V

b
) =
O
(

V

4
).
2. Let
P
be the algorithm that can determine whether a boolean formula
f
is satis±able or
not in polynomial time. That is,
P
(
f
) is true if
f
is satis±able, and
P
(
f
) is false otherwise.
Given a boolean formula
f
with
n
variables
x
1
,x
2
,
···
,x
n
, the following algorithm compute
a satisfying truth assignment
A
[1
..n
] for
x
i
s.
If P(f) is false then
report "f is not satisfiable."
else
g = f;
for each variable x_i in f do
if P(x_i and g) = true then
A[i] = true;
g = x_i and g; /* include a clause containing literal x_i to g */
else
A[i] = false;
g = not(x_i) and g; /* include a clause containing literal not(x_i) to g */
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Documentend if
end for
end if
The time taken by the algorithm is
O
(
n
·
T
(
g
)) where
g
contains
n
more clauses than
f
,
and
T
(
g
) is the time taken by
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '10
 Chan
 Algorithms

Click to edit the document details