### Tree reduction

←Return to chapter

## 4.3. Tree reduction

We reduce the problem of graph pattern matching to matching on rooted trees – as we will see in section 4.6, a much simpler problem to solve. The map between graphs and (rooted) trees is given by rooted dual trees. Call G GG tree-like if G GG is connected and the underlying undirected graph G U G_UG U​ of G GG is acyclic.

Definition 4.2Rooted dual tree

Let G GG be a tree-like graph with operations O O O. Then given a root operation r∈O r \in O r∈O, the rooted dual tree of G GG rooted at r r r, written τ r(G)\tau_r(G)τ r​(G) is the tree given by

- the nodes of the tree are the operations O O O of G GG,
- the parent and children of o∈O o \in Oo∈O are the operations that share a value with o oo in G GG; the parent is the unique operation on the path from o oo to r r r,
- the children of an operation are ordered according to the port labels.

Unlike graphs, tree nodes are identified uniquely by their path from the root. Trees isomorphic as graphs with identical root are thus considered equal.

#### A tree reduction using path splitting #

To reduce a graph G GG to a tree using the rooted dual tree construction, it suffices to reduce G GG to a tree-like graph. The following result shows that this can always be achieved by repeatedly applying operation splitting transformations.

Proposition 4.6Path splitting

A tree-like graph can be obtained from any connected graph G GG by applying operation splittings. The resulting graph is a path-split graph (PSG) of G GG.

Consider the undirected simple graph I\mathcal{I}I, where vertices are linear paths, and there is an edge between two linear paths for every operation that belongs to both paths. We call I\mathcal{I}I the interface graph of G GG.

Splitting an operation o oo in a graph G GG corresponds to removing the corresponding edge in I\mathcal{I}I. On the other hand, the underlying undirected graph G U G_UG U​ of G GG has a cycle if and only if there is a cycle in I\mathcal{I}I. Indeed, a cycle in G U G_UG U​ cannot belong to a single linear path in G GG, by acyclicity of minIR graphs. There is, therefore, a cycle of operations that span multiple linear paths, thus forming a cycle in I\mathcal{I}I.

Hence, the operations to be split to turn G GG into a tree-like graph are given by the set of edges E−E^-E− in I\mathcal{I}I that must be removed to obtain a spanning tree of I.\mathcal{I}.I.1

As we consider typed graph, the splitting of an operation is unique; however the choice of spanning tree of I\mathcal I I is not unique, and thus multiple PSGs exist for a given graph G GG.

If G′G'G′ is a PSG of some graph G GG, then call an operation o oo of G GG an anchor operation if it is on two linear paths and it is not split in G′G'G′. The set of all anchors operations π⊆O\pi \subseteq O π⊆O fully determines the path-split graph. We write G π=G′G^\pi = G'G π=G′ for the PSG of G GG obtained by anchors π\pi π.

Proposition 4.3Rooted dual trees are ternary
Consider a PSG G π G^\piG π of a graph G GG. There is a root operation r∈O r \in O r∈O such that the rooted dual tree τ r(G π)\tau_r(G^\pi)τ r​(G π) is a ternary tree, i.e. every node of τ r(G π)\tau_r(G^\pi)τ r​(G π) has at most three children.

We have assumed in section 4.2 that every operation in G GG is on at most two linear paths and thus can be connected to at most four values. Each value is linear and hence connected to at most one other operation. It results that every operation in τ r(G π)\tau_r(G^\pi)τ r​(G π) has at most four neighbouring operations – one parent and three children. A tree leaf can be chosen as the root operation to ensure the root does not have four children.

We can make the path splitting transformation G→G π G \to G^\piG→G π reversible by separately storing the set of split operations in G π G^\piG π that correspond to a single operation in G GG. As every operation of G GG can get split in at most two split operations, we can store the pairs of split operations in G π G^\piG π that correspond to an operation in G GG in a partial map that defines weights for (a subset of) the operations O π O^\pi O π of G π G^\piG π:

s p l i t: O π⇀P∗.split: O^\pi \rightharpoonup P^\ast.s pl it: O π⇀P∗.

This maps a split operation o oo to the unique undirected path in G π G^\piG π from o oo to the other half of the split operation.

This defines a map σ 1:(G π, s p l i t)↦G\sigma_1: (G^\pi, split) \mapsto G σ 1​:(G π, s pl it)↦G, the inverse of the path splitting transformation G→G π G \to G^\piG→G π.

#### Contracted path-split graphs #

We can further simplify the structure of the data of a PSG by contracting all operations of G π G^\piG π that are on a single linear path. The result is the contracted path-split graph (cPSG) of G GG, written c(G π)c(G^\pi)c(G π).

We employ a similar trick as above to make this transformation reversible, this time by introducing weights on the values of c(G π)c(G^\pi)c(G π) that store the string of operations that were contracted2

c o n t r a c t: V C⇀(Γ π)∗contract: V_C \rightharpoonup (\Gamma^\pi)^\astcont r act: V C​⇀(Γ π)∗

where V C V_C V C​ are the values of c(G π)c(G^\pi)c(G π) and Γ π\Gamma^\piΓ π are the optypes of operations in G π G^\piG π, i.e. the optypes of the minIR graph G GG along with the optypes of the split operations. This defines a second map σ 2:(c(G π),c o n t r a c t)↦G π\sigma_2: (c(G^\pi), contract) \mapsto G^\pi σ 2​:(c(G π),cont r act)↦G π that is the inverse of the path-split graph contraction transformation c(⋅)c(\cdot)c(⋅). In summary, we have the composition

(c(G π),c o n t r a c t, s p l i t)→σ 2×I d(G π, s p l i t)→σ 1 G.(c(G^\pi), contract, split) \xrightarrow{\sigma_2 \times Id} (G^\pi, split) \xrightarrow{\sigma_1} G.(c(G π),cont r act, s pl it)σ 2​×I d
​(G π, s pl it)σ 1​
​G.

Contracted PSGs are particularly useful for the study of the asymptotic complexity of the pattern matching algorithm we propose, as they have a very regular structure. This is expressed by the following proposition that further extends the statement of Proposition 4.3:

Proposition 4.4Contracted PSG
Consider a PSG G π G^\piG π of a graph G GG. There is a root operation r∈O r \in O r∈O such that the rooted dual tree of the contracted PSG τ r(c(G π))\tau_r(c(G^\pi))τ r​(c(G π)) is a ternary tree with w i d t h(G)−1 width(G) - 1 w idth(G)−1 nodes.

That the tree is ternary follows from Proposition 4.3. Every node of the tree corresponds to an operation in c(G π)c(G^\pi)c(G π), which is on exactly two linear paths. As a result of acyclicity of the tree, a tree of k k k nodes spans k+1 k+1 k+1 linear paths – and hence, we conclude k=w i d t h(G)−1 k = width(G) - 1 k=w idth(G)−1.

We conclude the construction presented in this section with the following result, expressing graph pattern matching in terms of tree equality:

Proposition 4.5Reduction to Tree Pattern matching

Let P P P be a pattern graph and G GG a graph. Let P π P^\pi P π be a PSG of G GG. There is an embedding P↪G P \hookrightarrow G P↪G if and only if there is H⊆G H \subseteq G H⊆G and a PSG H π′H^{\pi'}H π′ of H H H such that

τ(c(P π))=τ(c(H π′))\tau(c(P^\pi)) = \tau(c(H^{\pi'}))τ(c(P π))=τ(c(H π′))

and the trees have equal weight maps s p l i t splits pl it and c o n t r a c t contractcont r act.

The proof of this follows directly from our construction, the unicity of trees under isomorphism and the bijection between the graphs P, H P, H P, H and their cPSGs.

We have thus successfully reduced the problem of pattern matching to the problem of matching on trees. Given that the ordering of children of a node in a tree is fixed, checking trees for equality is a simple matter of checking node and weight equality, one node (and edge) at a time.

We conclude this section with a figure summarising the constructions we have presented.

A graph G GG, along with the path-split graph G π G^\piG π, the contracted path-split graph c(G π)c(G^\pi)c(G π) and their rooted dual trees. The anchor operations are d dd (grey) and e ee (red). The root of the rooted dual trees is e ee.

1. It is a simple result from graph theory that such a set of edges always exists – it suffices to remove one edge from every cycle in the graph. ↩︎

2. Because all contracted operations apply on a single, shared, linear path, they indeed form a string of operations. ↩︎

←Return to chapter