Vertex sets In one variation of monadic second-order graph logic known as MSO1, the
graph is described by a set of vertices and a binary adjacency relation \operatorname{adj}(.,.), and the restriction to monadic logic means that the graph property in question may be defined in terms of sets of vertices of the given graph, but not in terms of sets of edges, or sets of tuples of vertices. As an example, the property of a graph being
colorable with three colors (represented by three sets of vertices R, G, and B) may be defined by the monadic second-order formula \begin{align} \exists R\ \exists G\ \exists B\ \Bigl( & \forall v\ (v\in R \vee v\in G \vee v\in B) \wedge{} \\ & \forall u\ \forall v\ \bigl( (u\in R\wedge v\in R)\rightarrow\lnot\operatorname{adj}(u,v) \bigr) \wedge{} \\ & \forall u\ \forall v\ \bigl( (u\in G\wedge v\in G)\rightarrow\lnot\operatorname{adj}(u,v) \bigr) \wedge{} \\ & \forall u\ \forall v\ \bigl( (u\in B\wedge v\in B)\rightarrow\lnot\operatorname{adj}(u,v) \bigr) \Bigr) \end{align} with the
naming convention that uppercase variables denote sets of vertices and lowercase variables denote individual vertices (so that an explicit declaration of which is which can be omitted from the formula). The first part of this formula ensures that the three color classes cover all the vertices of the graph, and the rest ensures that they each form an
independent set. (It would also be possible to add clauses to the formula to ensure that the three color classes are disjoint, but this makes no difference to the result.) Thus, by Courcelle's theorem, 3-colorability of graphs of bounded treewidth may be tested in linear time. For this variation of graph logic, Courcelle's theorem can be extended from treewidth to
clique-width: for every fixed MSO1 property \Pi, and every fixed bound b on the clique-width of a graph, there is a linear-time algorithm for testing whether a graph of clique-width at most b has property \Pi. The original formulation of this result required the input graph to be given together with a construction proving that it has bounded clique-width, but later
approximation algorithms for clique-width removed this requirement.
Edge sets Courcelle's theorem may also be used with a stronger variation of monadic second-order logic known as MSO2. In this formulation, a graph is represented by a set
V of vertices, a set
E of edges, and an incidence relation between vertices and edges. This variation allows quantification over sets of vertices or edges, but not over more complex relations on tuples of vertices or edges. For instance, the property of having a
Hamiltonian cycle may be expressed in MSO2 by describing the cycle as a set of edges that includes exactly two edges incident to each vertex, such that every nonempty proper subset of vertices has an edge in the putative cycle with exactly one endpoint in the subset. However, Hamiltonicity cannot be expressed in MSO1.
Labeled graphs It is possible to apply the same results to graphs in which the vertices or edges have
labels from a fixed
finite set, either by augmenting the graph logic to incorporate predicates describing the labels, or by representing the labels by unquantified vertex set or edge set variables.
Space complexity Rather than bounding the
time complexity of an algorithm that recognizes an MSO property on bounded-treewidth graphs, it is also possible to analyze the
space complexity of such an algorithm; that is, the amount of memory needed above and beyond the size of the input itself (which is assumed to be represented in a read-only way so that its space requirements cannot be put to other purposes). In particular, it is possible to recognize the graphs of bounded treewidth, and any MSO property on these graphs, by a
deterministic Turing machine that uses only
logarithmic space. ==Proof strategy and complexity==