Algorithms for Graphs of Bounded

Made by Moshe Sebag CS department, Technion

The material for all parts of this lecture appears in Chapter 7 of the book "Parameterized ", by Cygan et al. Table of Content

 Into: explanation of the term "treewidth of a graph“  Definitions: 1. decomposition of a graph 2. Nice tree decomposition  Dynamic Programming (DP) on graphs of bounded treewidth  Example of DP-based for Weighted Independent Set  Run-time analysis of the algorithm  Treewidth and Monadic second-order Logic  Courcelle's theorem Treewidth of a Graph

 The treewidth of an undirected graph is a number associated with the graph.  Very roughly, treewidth captures how similar a graph is to a tree.  Treewidth is commonly used as a parameter in the analysis of graph algorithms.  In this lecture, we focus on connections to the idea of dynamic programming on the structure of a graph. Treewidth of a Graph

 The treewidth of an undirected graph is a number associated with the graph.  Very roughly, treewidth captures how similar a graph is to a tree.  Treewidth is commonly usedBut as ahow parameter do you in the parameterized complexitycalculateanalysis theof graph algorithms.  In this lecture, we focus on connectionstreewidth of to athe idea of dynamic programming on the structure ofgraph? a graph. Tree Decomposition

 a tree decomposition is a mapping of a graph into a tree that can be used to define the treewidth of the graph. Tree Decomposition

 Definition: a tree decomposition of a graph 퐺 is a pair 퓣 = (푇, 푋푡 푡∈푉 푇 ), where 푇 is a tree whose every node 푡 is assigned a subset 푋푡 ⊆ 푉 (퐺).  The following three conditions hold:

(푡∈푉(푇) 푋푡 = 푉(퐺ڂ( (T1

 (T2) For every 푢푣 ∈ 퐸(퐺) , there exists a node 푡 of 푇 such that bag 푋푡 contains both 푢 and 푣.

 (T3) For every 푢 ∈ 푉 (퐺), the set 푇푢 = {푡 ∈ 푉 (푇) ∶ 푢 ∈ 푋푡}, induces a connected subtree of T. Tree Decomposition

 Definition: a tree decomposition of a graph 퐺 is a pair 퓣 = (푇, 푋푡 푡∈푉 푇 ), where 푇 is a tree whose every node 푡 is assigned a vertex subset 푋푡 ⊆ 푉 (퐺).  The following three conditions hold:

(푡∈푉(푇) 푋푡 = 푉(퐺ڂ( (T1

 (T2) For every 푢푣 ∈ 퐸(퐺) , there exists a node 푡 of 푇 such that bag 푋푡 contains both 푢 and 푣. I still didn’t get  (T3) For every 푢 ∈ 푉 (퐺), the set 푇푢 = {푡 ∈ 푉 (푇) ∶ 푢 ∈ 푋푡}, induces a connected whatsubtree is theof T. TREEWIDTH? Treewidth by a Tree Decomposition

 After we defined what a tree composition is, we can define the treewidth of a graph.

 The width of tree decomposition 퓣 = (푇, 푋푡 푡∈푉 푇 ) equals max |푋푡| − 1, 푡∈푉 푇  The treewidth of a graph 퐺, denoted by 푡푤(퐺), is the minimum possible width of a tree decomposition of 퐺. Tree Decomposition Intro to Lemma 1.

 Definition 1: (퐴, 퐵) is a separation of a graph 퐺 if 퐴 ∪ 퐵 = 푉(퐺) and there is no edge between 퐴 \ 퐵 and 퐵 \ 퐴  Definition 2: Let (퐴, 퐵) be a separation of a graph, then 퐴 ∩ 퐵 is a separator of this separation, and |퐴 ∩ 퐵| is the order of the separation.

({A,B,C,D,E}, {B,E,F,G,H}) is a separation of the graph.

{B,E} is the separator Tree Decomposition Intro to Lemma 1.

 Definition 3: Let A be a subset of 푉(퐺), the border of A, denoted by ∂(A), is the set of those vertices of A that have a neighbor in 푉(퐺)\A.  For us the most crucial property of tree decompositions is that they define a sequence of separators in the graph.

For the subset {A,B,C,D,E}, ∂(A)={B,E} Tree Decomposition

 Lemma 1. Let (푇, 푋푡 푡∈푉 푇 ) be a tree decomposition of a graph 퐺 and let 푎푏 be an edge of 푇. The forest 푇 − 푎푏 obtained from 푇 by deleting edge ab consists of two connected components 푇푎 (containing a) and 푇푏 (containing b). Let K = 푋 and M = 푋 . 푡∈푉 (푇푏) 푡ڂ 푡∈푉 (푇푎) 푡ڂ Then 휕(퐾), 휕(푀) ⊆ 푋푎 ∩ 푋푏. Equivalently, (K, M) is a separation of G with separator 푋푎 ∩ 푋푏.

푎푏 ∈ 퐸(푇) Tree Decomposition

 Lemma 1. Let (푇, 푋푡 푡∈푉 푇 ) be a tree decomposition of a graph 퐺 and let 푎푏 be an edge of 푇. The forest 푇 − 푎푏 obtained from 푇 by deleting edge ab consists of two connected components 푇푎 (containing a) and 푇푏 (containing b). Let K = 푋 and M = 푋 . 푡∈푉 (푇푏) 푡ڂ 푡∈푉 (푇푎) 푡ڂ Then 휕(퐾), 휕(푀) ⊆ 푋푎 ∩ 푋푏. Equivalently, (K, M) is a separation of G with separator 푋푎 ∩ 푋푏. Tree Decomposition

 Lemma 1. Let (푇, 푋푡 푡∈푉 푇 ) be a tree decomposition of a graph 퐺 and let 푎푏 be an edge of 푇. The forest 푇 − 푎푏 obtained from 푇 by deleting edge ab consists of two connected components 푇푎 (containing a) and 푇푏 (containing b). Let K = 푋 and M = 푋 . 푡∈푉 (푇푏) 푡ڂ 푡∈푉 (푇푎) 푡ڂ Then 휕(퐾), 휕(푀) ⊆ 푋푎 ∩ 푋푏. Equivalently, (K, M) is a separation of G with separator 푋푎 ∩ 푋푏.

K= {A,B,C,D,E} M= {B,E,F,G,H} Tree Decomposition

 Lemma 1. Let (푇, 푋푡 푡∈푉 푇 ) be a tree decomposition of a graph 퐺 and let 푎푏 be an edge of 푇. The forest 푇 − 푎푏 obtained from 푇 by deleting edge ab consists of two connected components 푇푎 (containing a) and 푇푏 (containing b). Let K = 푋 and M = 푋 . 푡∈푉 (푇푏) 푡ڂ 푡∈푉 (푇푎) 푡ڂ Then 휕(퐾), 휕(푀) ⊆ 푋푎 ∩ 푋푏. Equivalently, (K, M) is a separation of G with separator 푋푎 ∩ 푋푏.

K= {A,B,C,D,E} M= {B,E,F,G,H}

푋푎= {C,B,E}

푋푏= {B,E,G}

푋푎 ∩ 푋푏 = {B,E} 휕(퐾) = {B,E} 휕(푀) = {B,E} Tree Decomposition

 Lemma 1. Let (푇, 푋푡 푡∈푉 푇 ) be a tree decomposition of a graph 퐺 and let 푎푏 be an edge of 푇. The forest 푇 − 푎푏 obtained from 푇 by deleting edge ab consists of two connected components 푇푎 (containing a) and 푇푏 (containing b). . 푋 ڂ = 푋 and M ڂ = Let K 푡∈푉 (푇푎) 푡 푡∈푉 (푇Wouldn푏) 푡 ’t it be Then 휕(퐾), 휕(푀) ⊆ 푋 ∩ 푋 . Equivalently, (K, M) is a separation of G with 푎 푏 complicated to separator 푋푎 ∩ 푋푏. plan the dynamic K= {A,B,C,D,E} programming on M= {B,E,F,G,H} TD? 푋푎= {C,B,E}

푋푏= {B,E,G}

푋푎 ∩ 푋푏 = {B,E} 휕(퐾) = {B,E} 휕(푀) = {B,E} Nice Tree Decomposition - motivation Nice Tree Decomposition

 We will think of a nice tree decompositions as rooted trees.

 A (rooted) tree decomposition (푇, 푋푡 푡∈푉 푇 ) is nice if the following conditions are satisfied:

 푋푟 = ∅ for 푟 the root of 푇 and 푋푙 = ∅ for every leaf 푙 of 푇.  Every non-leaf node of 푇 is of one of the following three types: Nice Tree Decomposition

 We will think of a nice tree decompositions as rooted trees.

 A (rooted) tree decomposition (푇, 푋푡 푡∈푉 푇 ) is nice if the following conditions are satisfied:

 푋푟 = ∅ for 푟 the root of 푇 and 푋푙 = ∅ for every leaf 푙 of 푇. Introduce  Every non-leaf node of 푇 is of one of the following three types: node: 1. Introduce node: ABC a node 푡 with exactly one child 푡′ such that 푋푡 = 푋푡′ ∪ {푣} for some vertex 푣 ∉ 푋푡′ (we say that 푣 is introduced at 푡).

AB Nice Tree Decomposition

 We will think of a nice tree decompositions as rooted trees.

 A (rooted) tree decomposition (푇, 푋푡 푡∈푉 푇 ) is nice if the following conditions are satisfied:

 푋푟 = ∅ for 푟 the root of 푇 and 푋푙 = ∅ for every leaf 푙 of 푇.  Every non-leaf node of 푇 is of one of the following three types: Forget node: 1. Introduce node: AB a node 푡 with exactly one child 푡′ such that 푋푡 = 푋푡′ ∪ {푣} for some vertex 푣 ∉ 푋푡′ (we say that 푣 is introduced at 푡). 2. Forget node: ′ a node 푡 with exactly one child 푡′ such that 푋푡 = Xt ∪ {w} for some vertex (we say that 푤 is forgotten at 푡).

ABC Nice Tree Decomposition

 We will think of a nice tree decompositions as rooted trees.

 A (rooted) tree decomposition (푇, 푋푡 푡∈푉 푇 ) is nice if the following conditions are satisfied:

 푋푟 = ∅ for 푟 the root of 푇 and 푋푙 = ∅ for every leaf 푙 of 푇. Join node:  Every non-leaf node of 푇 is of one of the following three types: 1. Introduce node: ABC a node 푡 with exactly one child 푡′ such that 푋푡 = 푋푡′ ∪ {푣} for some vertex 푣 ∉ 푋푡′ (we say that 푣 is introduced at 푡). 2. Forget node: ′ a node 푡 with exactly one child 푡′ such that 푋푡 = Xt ∪ {w} for some vertex (we say that 푤 is forgotten at 푡). 3. Join node: ABC ABC a node 푡 with two children 푡1, 푡2 such that 푋푡 = 푋푡1 = 푋푡2 . Nice Tree Decomposition

 We will think of a nice tree decompositions as rooted trees.

 A (rooted) tree decomposition (푇, 푋푡 푡∈푉 푇 ) is nice if the following conditions are satisfied:

 푋푟 = ∅ for 푟 the root of 푇 and 푋푙 = ∅ for every leaf 푙 of 푇. Edge node:  Every non-leaf node of 푇 is of one of the following three types: 1. Introduce node: ABC a node with exactly one child such that for some vertex {A->C} 푡 푡′ 푋푡 = 푋푡′ ∪ {푣} 푣 ∉ 푋푡′ (we say that 푣 is introduced at 푡). 2. Forget node: ′ a node 푡 with exactly one child 푡′ such that 푋푡 = Xt ∪ {w} for some vertex (we say that 푤 is forgotten at 푡). 3. Join node: ABC a node 푡 with two children 푡1, 푡2 such that 푋푡 = 푋푡1 = 푋푡2 . 4. Introduce edge node*: a node 푡, labeled with an edge 푢푣 ∈ 퐸(퐺) such that 푢, 푣 ∈ 푋푡, and with exactly ′ one child 푡′ such that 푋푡 = 푋푡 . (We say that edge 푢푣 is introduced at 푡). Nice Tree Decomposition

 We will think of a nice tree decompositions as rooted trees.

 A (rooted) tree decomposition (푇, 푋푡 푡∈푉 푇 ) is nice if the following conditions are satisfied:

 푋푟 = ∅ for 푟 the root of 푇 and 푋푙 = ∅ for every leaf 푙 of 푇. Edge node:  Every non-leaf node of 푇 is of oneIsn of’t the the following nice three tree types: 1. Introduce node: decomposition ABC a node 푡 with exactly one child 푡′ such that for some vertex {A->C} width bigger푋푡 = 푋then푡′ ∪ { 푣} 푣 ∉ 푋푡′ (we say that 푣 is introducedthe at TW 푡). of the 2. Forget node: graph? ′ a node 푡 with exactly one child 푡′ such that 푋푡 = Xt ∪ {w} for some vertex (we say that 푤 is forgotten at 푡). 3. Join node: ABC a node 푡 with two children 푡1, 푡2 such that 푋푡 = 푋푡1 = 푋푡2 . 4. Introduce edge node*: a node 푡, labeled with an edge 푢푣 ∈ 퐸(퐺) such that 푢, 푣 ∈ 푋푡, and with exactly ′ one child 푡′ such that 푋푡 = 푋푡 . (We say that edge 푢푣 is introduced at 푡). Nice Tree Decomposition

 Lemma 2. If a graph 퐺 admits a tree decomposition of width at most 푘, then it also admits a nice tree decomposition of width at most 푘.

 Moreover, given a tree decomposition 퓣 = (푇, 푋푡 푡∈푉 푇 ) of 퐺 of width at most 푘, one can in time 푂(푘2 · max(|푉 (푇)|, |푉 (퐺)|)) compute a nice tree decomposition of G of width at most k that has at most 푂(푘|푉(퐺)|) nodes.  Proof of the lemma and the algorithm of computing a (nice) tree decomposition are out of the scope of this lecture. Therefore, we will assume that such a decomposition is provided on the input together with the graph. Dynamic Programming Reminder

 Dynamic Programming(DP) is a technique to solve problems by breaking them down into overlapping sub-problems which follows the optimal substructure.  Dynamic programming is a class of problems where it is possible to store results for recurring computations in some lookup so that they can be used when required again by other computations.  This improves performance at the cost of memory.  We will focus on dynamic programming for graphs of bounded treewidth Dynamic Programming Reminder

 Dynamic Programming(DP) is a technique to solve problems by breaking them down into overlapping sub-problems which follows the optimal substructure.  Dynamic programming is a class of problems where it is possible to store results for recurring computations in someWhich lookup graphs so that are they can be used when required again by other computations.of bounded  This improves performance at the cost of treewidth?memory.  We will focus on dynamic programming on graphs of bounded treewidth Dynamic Programming on graphs of bounded treewidth

 Examples of graphs with bounded treewidth:  Pseudoforest graph: every connected has at most one . 푡푟푒푒푤𝑖푑푡ℎ = 2 Dynamic Programming on graphs of bounded treewidth

 Examples of graphs with bounded treewidth:  : any two simple cycles have at most one vertex in common 푡푟푒푒푤𝑖푑푡ℎ = 2 Dynamic Programming on graphs of bounded treewidth

 Examples of graphs with bounded treewidth:  outerplanar graph: has a planar drawing for which all vertices belong to the outer face of the drawing. 푡푟푒푒푤𝑖푑푡ℎ = 2 Dynamic Programming on graphs of bounded treewidth

 Examples of graphs with bounded treewidth:  Control flow graph (compilation): all paths that might be traversed through a program during its execution. 푡푟푒푒푤𝑖푑푡ℎ ≤ 6 Maximum Weighted Independent Set

 Independent Set: Given an undirected graph G=(V,E) an independent set (IS) of G is a subset 푆 ⊆ 푉, such that no two of its vertices are adjacent.  The problem: Given an undirected graph G=(V,E) and a weight function on its vertices 푤: 푉 → ℝ+, find a subset 푆 ⊆ 푉 such that 푆 ∈ 퐼푆 and ∀푆′ ∈ 퐼푆 ∶ 푤 푆 ≥ 푤(푆′).  The maximum weighted independent set is known to be NP-hard.  Therefore, it is unlikely that there exists an efficient algorithm for solving it.  However, we will now see a dynamic-programming-based algorithm that solves it efficiently on graphs of bounded treewidth. Weighted Independent Set – DP alg.

 Let G=(V,E) be a graph of n-vertex with width of at most k.

 And let 퓣 = (푇, 푋푡 푡∈푉 푇 ) be a tree decomposition of G.  By applying Lemma 2 we can assume that 퓣 is a nice tree decomposition. Weighted Independent Set – DP alg.  Let G=(V,E) be a graph of n-vertex with width of at most k.

 And let 퓣 = (푇, 푋푡 푡∈푉 푇 ) be a tree decomposition of G.  By applying Lemma 2 we can assume that 퓣 is a nice tree decomposition. Weighted Independent Set – DP alg intro.  Recall that 푇 is rooted at some node 푟.

 For a node 푡 of 푇, let 푉푡 be the union of all the bags present in the subtree of 푇 푡 rooted at 푡, including 푋푡. 푉푡  Provided that 푡 ≠ 푟 we can apply Lemma 1 to the edge of 푇 between 푡 and its parent, and infer that 휕 푉푡 ⊆ 푋푡 .  The same conclusion is trivial when 푡 = 푟. Weighted Independent Set Lemma 1. K = 푋 , .푡∈푉 (푇푎) 푡 – DP alg introڂ and  Recall that 푇 is rooted at some node 푟. M = 푋 , 푡∈푉 (푇푏) 푡ڂ (K, M) is a  For a node 푡 of 푇, let 푉푡 be the union of all separation of G the bags present in the subtree of 푇 푡 with separator rooted at 푡, including 푋푡. 푉푡 푋푎 ∩ 푋푏.  Provided that 푡 ≠ 푟 we can apply Lemma 1 to the edge of 푇 between 푡 and its parent, and infer that 휕 푉푡 ⊆ 푋푡 .  The same conclusion is trivial when 푡 = 푟. Weighted Independent Set – DP alg.

 Among independent sets 퐼 satisfying 퐼 ∩ 푋푡 = 푆 for some fixed 푆, all the maximum-weight solutions have exactly the same weight of the part contained in 푉푡. Weighted Independent Set – DP alg.

 Among independent sets 퐼 satisfying 퐼 ∩ 푋푡 = 푆 for some fixed 푆, all the maximum-weight solutions have exactly the same weight of the part contained in 푉푡.

 For every node 푡 and every 푆 ⊆ 푋푡, define the following value:

푐 푡, 푆 = 푚푎푥𝑖푚푢푚 푝표푠푠𝑖푏푙푒 푤푒𝑖푔ℎ푡 표푓 푎 푠푒푡 푆መ 푠푢푐ℎ 푡ℎ푎푡 푆 ⊆ 푆መ ⊆ 푉푡, 푆መ ∩ 푋푡 = 푆, 푎푛푑 푆መ 𝑖푠 𝑖푛푑푒푝푒푛푑푒푛푡. Weighted Independent Set – DP alg.

 Among independent sets 퐼 satisfying 퐼 ∩ 푋푡 = 푆 for some fixed 푆, all the maximum-weight solutions have exactly the same weight of the part contained in 푉푡.

 For every node 푡 and every 푆 ⊆ 푋푡, define the following value:

푐 푡, 푆 = 푚푎푥𝑖푚푢푚 푝표푠푠𝑖푏푙푒 푤푒𝑖푔ℎ푡 표푓 푎 푠푒푡 푆መ 푠푢푐ℎ 푡ℎ푎푡 푆 ⊆ 푆መ ⊆ 푉푡, 푆መ ∩ 푋푡 = 푆, 푎푛푑 푆መ 𝑖푠 𝑖푛푑푒푝푒푛푑푒푛푡.  If no such set 푆መ exists, then we put 푐[푡, 푆] = −∞ (iff S is not independent)  Final solution is 푐[푟, ∅]. Weighted Independent Set – DP alg.

 Among independent sets 퐼 satisfying 퐼 ∩ 푋푡 = 푆 for some fixed 푆, all the maximum-weight solutions have exactly the same weight of the part contained in 푉푡.

 For every node 푡 and every 푆 ⊆ 푋푡, define the following value:

푐 푡, 푆 = 푚푎푥𝑖푚푢푚 푝표푠푠𝑖푏푙푒 푤푒𝑖푔ℎ푡 표푓 푎 푠푒푡 푆መ 푠푢푐ℎ 푡ℎ푎푡 푆 ⊆ 푆መ ⊆ 푉푡, 푆መ ∩ 푋푡 = 푆, 푎푛푑 푆መ 𝑖푠 𝑖푛푑푒푝푒푛푑푒푛푡.  If no such set 푆መ exists, then we put 푐[푡, 푆] = −∞ (iff S is not independent)  Final solution is 푐[푟, ∅].  Now all we have to do is defining our recursive formulas for bottom-up DP. Weighted Independent Set – DP alg.

 Thanks to the definition of nice tree decomposition we have only few cases of how a bag relates to its children.  The computation 퐶[푡, 푆] for each node is based only on the values that were computed already for the children of this node.  Leaf node. If t is a leaf node, then we have only one value 푐[푡, ∅] = 0.

Leaf node Weighted Independent Set – DP alg.

 Introduce node. Suppose 푡 is an introduce node with ′ ′ child 푡′ such that 푋푡 = 푋푡 ∪ {푣} for some 푣 ∉ 푋푡 . Let 푆 be any subset of 푋푡. If 푆 is not independent, then we can immediately put 푐[푡, 푆] = −∞; hence assume otherwise. Then we claim that the following formula holds: Introduce node

* Weighted Independent Set – DP alg.

*

 Proof of *:  푣 ∈ 푆. Let 푆መ be the set that maximize 푐[푡, 푆].  푆መ ∖ {푣} was considered in the calculation of 푐[푡′, 푆 ∖ {푣}] (no other vertices were added, here nice tree helps us)  => 푐[푡′, 푆 ∖ {푣}] ≥ 푤(푆መ ∖ {푣}) = 푤(푆መ) − 푤(푣) = 푐[푡, 푆] − 푤(푣).

 => Weighted Independent Set – DP alg.

*

 Proof of * (cont.):  푣 ∈ 푆. Let 푆෡′ be the set that maximize 푐[푡′, 푆 ∖ {푣}].  푆 is independent (as we assume before) so 푣 doesn’t have ෡ neighbors in S ∖ {푣} = 푆′ ∩ 푋푡′ ′ ෡  Moreover, by lemma 1 , 푣 doesn’t have any neighbor in 푉푡 ∖ 푋푡′ ⊇ 푆′ ∖ 푋푡′  => 푣 Doesn’t have neighbor in 푆෡′ .푣} is independent Set}ڂ′ => 푆෡ ෡ .[푣} intersects with 푋푡 only at 푆 so this set was consider for 푐[푡, 푆}ڂ′ 푆 Weighted Independent Set – DP alg.

*

 Proof of * (cont.):  Now we can conclude:

 And from both conclusions we get: Weighted Independent Set – DP alg.

 Forget node. Suppose 푡 is a forget node with child 푡′ such that 푋푡 = 푋푡′ ∖ {푤} for some 푤 ∈ 푋푡 . Let 푆 be any subset of 푋푡 ; again we assume that S is independent, since otherwise we put c[t, S] = −∞. Forget node We claim that the following formula holds:

 Proof: Let 푆෡′ be a set that maximize 푐[푡, 푆]. If 푤 ∉ 푆෡′, so 푆෡′ was considered when calculating 푐[푡’, 푆] and hence 푐[푡’, 푆] ≥ 푤(푆෡′) = 푐[푡, 푆]. Else, If 푤 ∈ 푆෡′ so 푆෡′ was considered when calculating 푐[푡’, 푆 ∪ {푤}] and hence 푐[푡’, 푆 ∪ {푤}]] ≥ 푤(푆෡′) = 푐[푡, 푆]. Weighted Independent Set – DP alg.

 Forget node. Suppose 푡 is a forget node with child 푡′ such that 푋푡 = 푋푡′ ∖ {푤} for some 푤 ∈ 푋푡 . Let 푆 be any subset of 푋푡 ; again we assume that S is independent, since otherwise we put c[t, S] = −∞. Forget node We claim that the following formula holds: Weighted Independent Set – DP alg.

 Forget node. Suppose 푡 is a forget node with child 푡′ such that 푋푡 = 푋푡′ ∖ {푤} for some 푤 ∈ 푋푡 . Let 푆 be any subset of 푋푡 ; again we assume that S is independent, since otherwise we put c[t, S] = −∞. Forget node We claim that the following formula holds: Weighted Independent Set

– DP alg. Join node

 Join node. Finally, suppose that 푡 is a join node with children 푡1, 푡2 such that 푋푡 = 푋푡1 = 푋푡2 . Let 푆 be any subset of 푋푡; as before, we can assume that 푆 is independent. The recursive formula is as follows:

 Proof idea: from Lemma 1 we know that each part of 푡’s children is separated and the border is inside 푋푡 vertices. We take all of 푆(⊆ 푋푡) to be in 푐 푡, 푆 . So we will consider the best solution of each child for S and subtract its size once (because we took it twice). Run-time analysis of the algorithm

 We have treewidth of at most 푘, which means 푋푡 ≤ 푘 + 1 for every node 푡.  Thus for every node 푡 we compute 2 푋푡 ≤ 2푘+1 values of 푐[푡, 푆]  In naive solution we will say that each 푐[푡, 푆] computed in 푛푂 1 time. It is possible to construct a data structure that allows performing adjacency queries in time 푂 푘 , so computing each 푐 푡, 푆 will take only 푘푂 1 time.  we assumed that the number of nodes of the given tree decompositions is 푂(푘푛) (Lemma 2)  the total running time of the algorithm is 2푘 · 푘푂 1 · 푛

We’ve got a FPT algorithm for a problem that is known to be NP-hard! Run-time analysis of the algorithm

Just for graphs of bounded  We have treewidth of at most 푘, which means 푋푡 ≤ 푘 + 1 for every node 푡. treewidth  Thus for every node 푡 we compute 2 푋푡 ≤ 2푘+1 values of 푐[푡, 푆] though  In naive solution we will say that each 푐[푡, 푆] computed in 푛푂 1 time. It is possible to construct a data structure that allows performing adjacency queries in time 푂 푘 , so computing each 푐 푡, 푆 will take only 푘푂 1 time.  we assumed that the number of nodes of the given tree decompositions is 푂(푘푛) (Lemma 2)  the total running time of the algorithm is 2푘 · 푘푂 1 · 푛

We’ve got a FPT algorithm for a problem that is known to be NP-hard! Monadic second-order Logic

 In the course of Logic we saw First-Order Logic, where we can use quantifiers only over variables that range over individuals (∀푥 푎푛푑 ∃푥). ∀푥∀푦 푅 푥, 푦 → ¬푅 푦, 푥 (푎 − 푠푦푚푚푒푡푟𝑖푐 푑푒푓. )  second-order logic is an extension of it, that allows us to use quantifiers over relations, functions and sets of elements.  monadic second order logic (푴푺푶) is the fragment of second-order logic where the second-order quantification is limited to be only over sets.

 푴푺푶ퟐ allows quantification over sets of vertices or edges.  Our main interest here is to use MSO to describe properties of undirected graphs.  We view an undirected graph as relational structure (i.e. a model as in logic), where the universe is the vertices and there is one binary relation 퐸(푥, 푦) for the edges.

 Expmle for such 푴푺푶ퟐ formula that express 3-coloring in a graph:

∃푋1∃푋2∃푋3 ∀푥 ሧ 푋푖 ∧ ∀푥∀푦 퐸 푥, 푦 → ሧ 푋푖 푥 ∧ 푋푗(푥) 푖 푖≠푗 Courcelle's theorem

 Courcelle's theorem. Assume that 휙 is a formula of 푀푆푂2 and 퐺 is an n- vertex graph. Suppose, moreover, that a tree decomposition of 퐺 of width 푡 is provided. Then there exists an algorithm that verifies whether ϕ is satisfied in G in time 푓(||휙||, 푡) · 푛, for some computable function f.  In other words, every definable in the monadic second- order logic of graphs can be decided in linear time on graphs of bounded treewidth. Courcelle's theorem

 Courcelle's theorem. Assume that 휙 is a formula of 푀푆푂2 and 퐺 is an n- vertex graph. Suppose, moreover, that a tree decomposition of of width So which more 퐺 푡 is provided. Then there exists an algorithm that verifies whether is problems are ϕ satisfied in G in time 푓(||휙||, 푡) · 푛, for some computable function f. tractable now?  In other words, every graph property definable in the monadic second- order logic of graphs can be decided in linear time on graphs of bounded treewidth. Courcelle's theorem

 Courcelle's theorem. Assume that 휙 is a formula of 푀푆푂2 and 퐺 is an n- vertex graph. Suppose, moreover, that a tree decomposition of of width So which more 퐺 푡 is provided. Then there exists an algorithm that verifies whether is problems are ϕ satisfied in G in time 푓(||휙||, 푡) · 푛, for some computable function f. tractable now?  In other words, every graph property definable in the monadic second- order logic of graphs can be decided in linear time on graphs of bounded treewidth. That’s all, Thank you for listening

Any questions?