### Appendix

Appendix

## A. Prefix trees

Our main result is achieved by reducing a tree inclusion problem to the following problem.

String prefix matching.Consider the following computational problem over strings. Let Σ\SigmaΣ be a finite alphabet and consider W=(Σ∗)w\mathcal{W} = (\Sigma^*)^w W=(Σ∗)w the set of w w w-tuples of strings over Σ\SigmaΣ. For a string tuple (s 1,…,s w)∈W(s_1, \dots, s_w) \in \mathcal{W}(s 1​,…,s w​)∈W and a set of string tuples D⊆W\mathcal{D} \subseteq \mathcal{W}D⊆W, the w w w-dimensional string prefix matching consists in finding the set

{(p 1,…,p w)∈D ∣ for all 1≤i≤w: p i is a prefix of s i}.\{ (p_1, \dots, p_w) \in \mathcal{D} \ | \ \text{for all }1 \leq i \leq w: p_i\text{ is a prefix of }s_i \}.{(p 1​,…,p w​)∈D ∣ for all 1≤i≤w: p i​ is a prefix of s i​}.

This string problem can be solved using a w w w-dimensional prefix tree. We give a short introduction to prefix trees for the string case but refer to standard literature for more details Knuth, 1999Donald Knuth. 1999. The Art of Computer Programming: Sorting and Searching, Volume 3. Addison-Wesley, Reading MA.

One-dimensional prefix tree.Let P 1,…,P ℓ∈A∗P_1, \dots, P_\ell \in \mathcal{A}^\ast P 1​,…,P ℓ​∈A∗ be strings on some alphabet A\mathcal{A}A. Given an input string s∈A∗s\in\mathcal{A}^\asts∈A∗, we wish to find the set of patterns {P 1≤i≤ℓ∣P i⊆s}\{ P_{1 \leq i \leq \ell} | P_i \subseteq s\}{P 1≤i≤ℓ​∣P i​⊆s}, i.e. P i P_i P i​ is a prefix of s ss.

The prefix tree of P 1,…,P ℓ P_1, \dots, P_\ell P 1​,…,P ℓ​ is a tree with a tree node for each prefix of a pattern. The children of an internal node are the strings that extend the prefix by one character. The root of the tree is the empty string. Each tree node also stores a list of matching patterns, with each pattern stored in the unique corresponding node. Every prefix tree has an empty string node, which is the root of the tree. For every inserted pattern of length at most L LL nodes are inserted, one for every non-empty prefix of the pattern. Thus a one-dimensional prefix tree has at most ℓ⋅L+1\ell \cdot L + 1ℓ⋅L+1 nodes and can be constructed in time O(ℓ⋅L)O(\ell \cdot L)O(ℓ⋅L).

Given an input s∈A∗s \in \mathcal{A}^\asts∈A∗, we can find the set of matching patterns by traversing the prefix tree of P 1,…,P ℓ P_1, \dots, P_\ell P 1​,…,P ℓ​ starting from the root. We report the list of matching patterns at the current node and move to the child node that is still a prefix of s ss, if it exists. This procedure continues until no more such child exists. In total the traversal takes time O(∣s∣)O(|s|)O(∣s∣), as every character of s ss is visited at most once.

Note that in theory the number of reported pattern matches can dominate the runtime of the algorithm. We can avoid this by returning the list of matches as an iterator, stored as a list of pointers to the tree nodes matching lists.

Multi-dimensional prefix tree.A w w w-dimensional prefix tree for w>1 w > 1 w>1 is defined recursively as a one-dimensional prefix tree that at each node stores a w−1 w-1 w−1-dimensional prefix tree. Given an input w w w-tuple (s 1,…,s w)∈(A∗)w(s_1, \dots, s_w) \in (\mathcal{A}^\ast)^w(s 1​,…,s w​)∈(A∗)w, the traversal of the w w w-dimensional prefix tree is done by traversing the one-dimensional prefix tree on the input s 1 s_1s 1​ until no child is a prefix of the input, and then recursively traversing the w−1 w-1 w−1-dimensional prefix tree on (s 2,…,s w)(s_2, \dots, s_w)(s 2​,…,s w​). Similarly to the one-dimensional case, the list of matching patterns is stored at prefix tree nodes and reported during traversal. The traversal thus takes time O(∣s 1∣+⋯+∣s w∣)O(|s_1| + \cdots + |s_w|)O(∣s 1​∣+⋯+∣s w​∣), as every character of s ss is visited at most once.

For ℓ\ellℓ tuples of size w w w of words of maximum length L LL, we can bound the number of nodes of the w w w-dimensional prefix tree by 1+(ℓ⋅L)w 1 + (\ell \cdot L)^w1+(ℓ⋅L)w. The runtime and space complexity of the construction of the w w w-dimensional prefix tree is thus in O((ℓ⋅L)w)O((\ell \cdot L)^w)O((ℓ⋅L)w), summarised in the result:

Proposition 99.1Multi-dimensional string prefix matching
Let D⊆W\mathcal{D} \subseteq \mathcal{W}D⊆W be a set of string tuples and L LL the maximum length of a string in a tuple of D\mathcal{D}D. There is a prefix tree with at most (ℓ⋅L)w+1(\ell \cdot L)^w + 1(ℓ⋅L)w+1 nodes that encodes D\mathcal{D}D that can be used to solve the w w w-dimensional string prefix matching problem in time O(∣s 1∣+⋯+∣s w∣)O(|s_1| + \cdots + |s_w|)O(∣s 1​∣+⋯+∣s w​∣).

## B. Lower bound on the number of patterns

Proposition 99.2

Let N w, d N_{w,d}N w,d​ be the number of port graphs of width w w w, depth d dd and maximum degree Δ≥4\Delta \geq 4Δ≥4. We can lower bound

N w, d>(w 2 e)Θ(w d),N_{w,d} > \left(\frac{w}{2e}\right)^{\Theta(wd)},N w,d​>(2e w​)Θ(w d),

assuming w≤o(2 d)w \leq o(2^d)w≤o(2 d).

In the regime of interest, w w w is small, so the assumption w≤o(2 d)w \leq o(2^d)w≤o(2 d) is not a restriction.

Let w, d>0 w, d > 0 w, d>0 and Δ≥4\Delta \geq 4Δ≥4 be integers. We wish to lower bound the number of port graphs of depth d dd, width w w w and maximum degree Δ\DeltaΔ. It is sufficient to consider a restricted subset of such port graphs, whose size can be easily lower bounded. We will count a subset of CX quantum circuits, i.e. circuits with only C X CX CX gates, a two-qubit non-symmetric gate. Because we are using a single gate type, this is equivalent to counting a subset of port graphs with vertices of degree 4. Assume w.l.o.g that w w w is a power of two. We consider CX circuits constructed from two circuits with w w w qubits composed in sequence:

- Fixed tree circuit: A log⁡2(w)\log_2(w)log 2​(w)-depth circuit that connects qubits pairwise in such a way that the resulting port graph is connected. We fix such a tree-like circuit and use the same circuit for all CX circuits. We can use this common structure to fix an ordering of the w w w qubits, that refer to as qubits 1,…,w 1,\dots,w1,…,w.
- Bipartite circuit: A CX circuit of depth D=d−log⁡2(w)D = d - \log_2(w)D=d−log 2​(w) with exactly CX gates, each gate acting on a qubit and a qubit .

The following circuit illustrates the construction:

All that remains is to count the number of such bipartite circuits. Every slice of depth 1 must have w/2 w / 2 w/2 CX gates acting on distinct qubits. Every qubit 1 11 to w/2 w/2 w/2 must interact with one of the qubits w/2+1 w/2+1 w/2+1 to w w w, so there are (w/2)!(w/2)!(w/2)! such depth 1 slices. Repeating this depth 1 construction D D D times and using Sterling’s approximation, we obtain a lower bound for the number of port graphs of depth d dd, width w w w and maximum degree at least 4:

((w 2)!)D>w π(w 2 e)w D/2=(w 2 e)Θ(w⋅d)\left(\left(\frac{w}2\right)!\right)^D > \sqrt{w\pi}\left(\frac{w}{2e}\right)^{wD/2} = \left(\frac{w}{2e}\right)^{\Theta(w\cdot d)}((2 w​)!)D>w π
​(2e w​)w D/2=(2e w​)Θ(w⋅d)

where we used w=o(2 d)w = o(2^d)w=o(2 d) to obtain Θ(D)=Θ(d)\Theta(D) = \Theta(d)Θ(D)=Θ(d) in the last step.