Courcelle`s Theorem 1 Overview 2 Background

Advanced Graph Algorithms
Jan-Apr 2014
Courcelle’s Theorem
Speaker: Anantha Padmanabha MS
1
Date: April 29, 2014
Overview
In this lecture, we shall see Courcelle’s theorem and its proof in a nutshell. This result was first
proved by Bruno Courcelle in 1990 and is considered the archetype of algorithmic meta-theorems.
The statement of the theorem is the following :
Theorem 1. Given a graph G = (V, E) of tree width w, and an MSO sentence φ, G |= φ can be
decided in time O(f (|φ|, w) · |G|).
2
Background
To prove this theorem, we need to know about Monoidic second order logic and Regular tree
languages.
2.1
Monoidic second order logic (MSO)
The syntax of Monoidic second order logic over the Domain D is given as follows :
• t → x ∈ variable |c ∈ constant |f (t1 , · · · tn ), where f ∈ functions
• φ → P redicate(t1 , · · · tm ) | ¬φ1 | φ1 ∨ φ2 | ∃xφ1 , where x ∈ D | ∃Xφ1 , where X ⊆ D
Informally, monoidic second order logic has all the powers of the first order logic and in addtion to
that, quantification over the subset of the domain is also allowed. As a convention we use captial
letters to quantify over subsets and small letters to quantify over elements.
MSO on graphs: In this lecture, we are interested in the graph properties which are expressible
in MSO. Let us see a few examples :
1. A Graph is 3-colourable
∃X1 ∃X2 ∃X3 (∀x(X1 x ∧ ¬X2 x ∧ ¬X3 x) ∨ (¬X1 x ∧ X2 x ∧ ¬X3 x) ∨ (¬X1 x ∧ ¬X2 x ∧ X3 x))∧
(∀x∀yExy =⇒ (¬(X1 x ∧ X1 y) ∧ ¬(X2 x ∧ X2 y) ∧ ¬(X3 x ∧ X3 y))
2. A Graph has a dominator size of set k
∃x1 ∃x2 · · · ∃xk ∀x(
k
_
x = xi ) ∨ ∃y(Exy ∧
i=1
k
_
i=1
1
y = xi )
2.2
Tree Automaton
A Tree Automaton is a Finite state machine which is used to recognize Tree languages. A Tree
language is the set of all trees whose vertices are labelled from a fixed Σ and satisfies some required
properties. For our current topic, we restric ourselves only to binary trees.
Suppose Σ = {a, b} and T = {T | T is a labelled binary tree}, then an example for a tree language
is L = {T ∈ T | Total number of “a” labelled nodes ≤ 5}
A deterministic bottom-up tree automaton is A = (Q, Σ, δ, F ) where
• Q is a set of finite states
• Σ is the alphabet used to label the tree nodes
• F ⊆ Q is the set of final states
• δ : Q ∪ {⊥} × Q ∪ {⊥} × Σ → Q
The Automaton starts associating the nodes of the input tree with some states starting from the
leaf and finally the input tree is accepted if the state associated with the root node ∈ F
A Tree Language N is said to be regular if there exists a deterministic tree automaton A such
that L(A) = N .
Theorem 2. A tree language L is MSO definable iff L is regular.
The proof of this theorem is not discussed in this lecture, but we note that the proof for ⇐ is done
by inductively constructing the tree automaton for an MSO sentence depending on its structure.
We shall use this property as a part of our algorithm.
3
Proof of Courcelle’s theorem
Let us describe an algorithm which takes a Graph G and an MSO sentence φ as inputs and decide
whether G |= φ.
Courcelle
Input: Graph G(V, E) of tree width w and an MSO sentence φ
Output: whether G |= φ or not
Step 1: Construct TG ← Tree-Decompostion(G)
Step 2: T ← Label the vertices of TG by a suitable Σ
Step 3: Construct MSO sentence φ0 such that G |= φ iff T |= φ0
Step 4: Check if T |= φ0 and return the Y es\N o accordingly.
2
The correctness of the Algorithm is clear from the construction. We shall prove that the running
time of this algorithm is O(f (|φ|, w) · |G|).
3.1
Step 1 and Step 3
In the first step, we construct the tree decomposition of the given graph. Bodlaender[1] proved
that there is an algorithm which given a graph G as input, constructs a tree-decomposition of
2
G of width w in time O(2w · |G|). We shall use this algorithm in step 1 to construct the tree
Decomposition of G.
For the third step, we use Theorem[2] to construct the tree automaton A for φ0 and then check if
A accepts T . Constructing A takes O(f (|φ0 |)) time and checking if A accepts G takes O(|G|) time.
Thus if we are able to achieve Step 2 and Step 3 in O(f (|φ|, w) · |G|) then it concludes the proof.
3.2
Step 2
Without loss of generality, we can assume that TG is a binary tree. Every S ⊆ VG of size at most
w + 1 can be encoded as a string of length w + 1 − list the elements of S in some (canonical) order,
and repeat some to ensure that the string is of length exactly w + 1.
Thus, we have a a tree decomposition TG = (VT , ET , BT ) of width w for graph G = (VG , EG )
such that BT : VT → VGw+1 . Note that |VT | = O(|VG |).
Labelling the vertices of T We could have used BT itself as the label for the vertices of T .
But the problem is that BT is dependent on the size of |G|, but to label the vertices of a tree we
need a fixed Σ.
Hence, we construct T (VT , ET , LT ) with a new label for vertices of T using a fixed Σ. LT is
defined as follows : ∀u ∈ VT , L(u) = (λ1 , λ2 , λ3 ) where,
• λi ⊆ {1, 2, · · · w + 1} × {1, 2, · · · w + 1}, for i = 1, 2, or 3.
• λ1 = {(i, j)| ith vertex in BT (u) and j th vertex in BT (u) have an edge between them in G}
• λ2 = {(i, j)| ith vertex in BT (u) and j th vertex in BT (u) are the same }
• λ3 = {(i, j)| ith vertex in BT (u) and j th vertex in BT (v) are the same, where v is the parent
of u in TG }
3
Example
Consider the following graph and its corresponding tree-decomposition.
ABA(a)
A
ABC(b)
B
F
ACD(c)
C
E
ADE(d)
D
AEF(e)
AFA(f)
The corresponding labelling would be as follows :
• LT (a) = {(12, 21, 23, 32)(13, 31)()}
• LT (b) = {(12, 21, 23, 32)()(11, 13)}
• LT (c) = {(23, 32)()(11, 23)}
• LT (d) = {(23, 32)()(11, 23)}
• LT (e) = {(13, 31, 23, 32)()(11, 23)}
• LT (f ) = {(12, 21, 23, 32)(13, 31)(11, 31, 23)}
Note that the new labelling depends only on w and not on the size of G and hence has a constant
Σ. Also, this labelling can be computed in O(|VT |) = O(|VG |) = O(|G|) time.
3.3
Step 3
In this step we need to construct φ0 such that, G |= φ iff T |= φ0 . To do this, we need to encode
the vertices of G as tuples of vertices of T
Any S ⊆ VG is encoded as T ree(S) = (U1 , U2 , · · · , Uw+1 ), where Ui ⊆ VT such that
Ui = {v ∈ VT | ith value in BT (v) ∈ S}
For the above example, T ree({A, C, E}) = ({a, b, c, d, e, f }, {}, {a, b, d, f })
T ree({A}) = ({a, b, c, d, e, f }, {}, {a, f })
4
It is important to note that, not every tuple of vertices of trees correspond to a vertex in the
graph. For instance, in the above example ({a}, {}, {}) is not T ree(S) for any S.
Lemma 3. A tuple of sets of nodes of TG , X = (X1 , · · · Xw+1 ) is the encoding T ree(S) for some
S with |S| ≥ 1 iff
(a) If (i, j) ∈ λ2 (u) then u ∈ Xi iff u ∈ Xj .
(b) If (i, j) ∈ λ3 (u) then u ∈ Xi iff v ∈ Xj , where v is the parent of u.
X is T ree(S) for some S with |S| = 1 iff (a) and (b) holds and
(c) If u ∈ Xi and u ∈ Xj then (i, j) ∈ λ2 (u).
(d) If u ∈ Xi ,v ∈ Xj (where v is parent of u) then (i, j) ∈ λ3 (u).
(e)
w+1
S
Xi forms a connected component of TG .
i=1
Proof. ⇒ is easy to see in both the cases.
We need to prove ⇐
Case |S| ≥ 1
Let X = (X1 , · · · Xw+1 ) be a tuple that satisfies (a) and (b).
Define (Set(X) = {x ∈ VG | ∃i∃u, u ∈ Xi and ith position in BT (u) = x}
Claim : T ree(Set(X) = X
Suppose not, then there are u1 and u2 such that ith position in BT (u1 ) = j th position in BT (u2 ) = x
such that u1 ∈ X and u2 6∈ X
• Since x ∈ BT (u1 ) and x ∈ BT (u2 ), x appears in the label of every vertex on the path from
u1 to u2 .
• Thus, without loss of generality, we may assume that either u1 = u2 or u1 is parent of u2 .
• But then X violates (a) if u1 = u2 and X violates (b) if u1 is the parent of u2 , which
contradicts the fact that X satisfies both (a) and(b).
Case |S| = 1
Let X satisfy (a), (b), (c), (d) and (e), once again consider S = Set(X)
Since X satisfies (a) and (b), by the previous result X is a valid tuple for S. Claim: |S| = 1
Suppose not, then |S| > 1 and there are vertices u1 and u2 and i and j such that u1 ∈ X1 , u2 ∈ Xj ,
and ith position in BT (u1 ) = j th position in BT (u2 ).
• Since X satisfies (e), without loss of generality, u1 = u2 or u1 is the parent of u2 .
• But then, X violates (c) and (d).
5
Once we have proved the validity condition of the tuples, we can encode these conditions in the
form of MSO sentence. Let φa φb φc φd φe denote the encoding of the conditions (a) (b) (c) (d) (e)
respectively.
V
• φa (X1 , · · · Xw+1 ) = ∀x
V
(Xi x ⇐⇒ Xj x)
i,j∈{1,2···w+1} a:(i,j)∈λ2 (a)
V
• φb (X1 , · · · Xw+1 ) = ∀x∀y
V
ETG xy =⇒ (Xi x ⇐⇒ Xj x)
i,j∈{1,2···w+1} a:(i,j)∈λ3 (a)
W
• φc (X1 , · · · Xw+1 ) = ∀x((Xi x ∧ Xj x) =⇒
Qa x
a:(i,j)∈λ2 (a)
• φd (X1 , · · · Xw+1 ) = ∀x∀y((Xi x ∧ Xj y ∧ ETG yx) =⇒
W
Qa x
a:(i,j)∈λ3 (a)
w+1
S
• φ2 (X1 , · · · Xw+1 ) = Connected(
Xi ) where,
i=1
Connected(Y ) = ∀Y1 ∀Y2 ((Y1 ∪ Y2 = Y ) ∧ (Y1 ∩ Y2 = Φ) ∧ Y1 6= Φ ∧ Y2 6= Φ) =⇒
(∃x∃yY1 x ∧ Y2 y ∧ ETG xy)
Now we are ready to construct MSO φ0 such that given φ(x1 , x2 , · · · xn , Y1 , Y2 , · · · Ym ) we construct
φ0 (X1 , X2 , · · · Xn , Y1 , Y2 · · · Ym such that
G |= φ(x1 , x2 , · · · xn , Y1 , Y2 , · · · Ym ) ⇐⇒ TG |= φ0 (X1 , X2 , · · · Xn , Y1 , Y2 · · · Ym )
φ0 is constructed inductively :
Base case
w+1
V
• Case φ : (x1 = x2 ) then φ0 :
X1i = X2i
i=1
• Case φ : EG xy then φ0 : ∃u
W
Xai u ∧ Xaj u ∧ Qa u
a:(i,j)∈λ2 (a)
• Case φ : Y x then φ0 :
w+1
V
Xi ⊆ Yi
i=1
Induction step :
• Case φ : φ1 ∧ φ2 then φ0 : φ01 ∧ φ02
• Case φ : φ1 ∨ φ2 then φ0 : φ01 ∨ φ02
• Case φ : ¬φ1 then φ0 : ¬φ01
• Case φ : ∃Y φ1 then φ0 : ∃Y (φa (Y ) ∧ φb (Y ) ∧ φ01 )
• Case φ : ∃xφ1 then φ0 : ∃X(φa (X) ∧ φb (X) ∧ φc (X) ∧ φd (X) ∧ φe (X) ∧ φ01 )
6
References
[1] Hans L. Bodlaender: A Linear-Time Algorithm for Finding Tree-Decompositions of Small
Treewidth.SIAM J. Comput.25(6): 1305-1317,1996
7