1 Introduction

Associativity is a fundamental property of binary operations, and one tends to take it for granted, since the most frequently encountered operations are associative. However, there are also many noteworthy operations that are not associative, such as subtraction, cross product of vectors, implication, just to name a few. For a systematic study of phenomena related to (non)associativity, one may consider an arbitrary nonempty set A together with a binary operation \( x\cdot y\) on A. Let us emphasize that we denote the operation as multiplication only for notational convenience; the operation can be any map \(A \times A \rightarrow A,\ (x,y) \mapsto x \cdot y\). This yields the algebraic structure \(\mathbb {A}= (A; {\cdot })\), called a groupoid. (Note that the term groupoid has a different meaning in category theory.)

Given such a groupoid, there are several ways of measuring how far our operation is from being associative. For finite A, a natural “measure of nonassociativity” is the number of triples \((a,b,c) \in A^3\) such that \((a \cdot b) \cdot c \ne a \cdot (b \cdot c)\). This notion was studied by A. C. Climescu [5] as early as 1947, and later by T. Kepka and M. Trch in a long series of papers starting with [11]. Another option is to count the minimum number of changes one has to make in the operation table in order to make it associative [12].

B. Csákány suggested a third method, namely to look at how many of the identities that are consequences of associativity are (not) satisfied. If the operation is associative, then there is no need to use parentheses in a product \(x_1 \cdot x_2 \cdot \ldots \cdot x_n\), as the result will be the same anyway, but if the operation is not associative, then one must insert \(n-2\) pairs of parentheses in order to make the product unambiguous. The Catalan numbers \(C_{n-1} = \frac{1}{n} \left( {\begin{array}{c}2n-2\\ n-1\end{array}}\right) \) give the number of ways of inserting parentheses (or round brackets) meaningfully, and each such bracketing induces an n-variable function \(A^n \rightarrow A\). For associative binary operations, all these n-ary functions will be the same, but for arbitrary operations we may get as many as \(C_{n-1}\) functions. The associative spectrum of \(\mathbb {A}\) is the sequence \(\{s_n(\mathbb {A})\}_{n=1}^\infty \) that counts the number of different n-ary functions on A arising from bracketings of the product \(x_1 \cdot x_2 \cdot \ldots \cdot x_n\). If \(\mathbb {A}\) is a semigroup (i.e., if \(x \cdot y\) is associative), then \(s_n(\mathbb {A})=1\) for all \(n \in \mathbb {N}\), and intuitively we can say that the faster the spectrum grows, the less associative the operation is.

The associative spectrum was introduced in [7], and some basic properties and many examples of associative spectra were presented. In particular, it was shown that the cross product and the implication have a Catalan spectrum; hence, they are as nonassociative as a binary operation can be. We shall call such operations (groupoids) antiassociative. The associative spectrum of the subtraction operation is given by \(s_n=2^{n-2}\); thus, subtraction is somewhere between being associative and antiassociative. Examples of groupoids with constant and linear spectra were also given in [7]; furthermore, in [14] groupoids with polynomial spectra of arbitrary degrees were constructed. It was also proved in [14] that there exist a continuum of different associative spectra (allowing infinite base sets, of course). Similar questions were investigated in [2,3,4], where some of the earlier results were rediscovered (with a different terminology).

In this paper, we study associative spectra of certain binary operations associated to graphs, which may be finite or infinite. Let us define a “multiplication” on the vertices of a graph as follows: let \(u \cdot v = u\) if there is an edge from u to v and let \(u \cdot v = \infty \) otherwise (here \(\infty \) is an external absorbing element). We define the arising graph algebras more precisely in Sect. 2, where we also present the required background on bracketings and spectra.

For undirected graphs, we obtain a full description of all possible associative spectra in Sect. 3. It turns out that there are only three possibilities: we have either \(s_n=1\), \(s_n=2^{n-2}\) or \(s_n=C_{n-1}\). Note the sharp contrast between this result and the abundance of different (growth rates of) spectra presented in [7, 14]. In Theorem 3.3, we also give explicit characterizations of undirected graphs corresponding to each of the three spectra.

We determine antiassociative digraphs in Sect. 4; this together with the description of associative digraphs [15] gives us at least a picture about the two extrema of the spectrum(!) of associative spectra of digraphs. Finally, in Sect. 5 we compute the associative spectra of some concrete graphs such as cycles and paths, and we also determine the spectra of graphs on two vertices. A more detailed analysis of the associative spectra of general digraphs will be a topic of a forthcoming paper.

2 Preliminaries

2.1 General notation

We denote by \(\mathbb {N}\) and \(\mathbb {N}_{+}\) the set of nonnegative integers and the set of positive integers, respectively. For \(a, b \in \mathbb {N}\), let \([a,b] := \{i \in \mathbb {N}\mid a \le i \le b\}\). (Thus \([a,b] = \emptyset \) if \(a > b\).) For \(n \in \mathbb {N}\), let \([{n}] := [1,n] = \{1, \dots , n\}\).

2.2 Directed graphs

By a directed graph (or digraph or simply graph), we mean a pair \(G = (V, E)\), where \(V = V(G)\) is a nonempty set of vertices and \(E = E(G) \subseteq V^2\) is a set of edges (or the edge relation). A digraph \(G' = (V', E')\) is a subgraph of \(G = (V,E)\) if \(V' \subseteq V\) and \(E' \subseteq E\); it is an induced subgraph of G if additionally \(E' = E \cap (V' \times V')\).

If \(e = (u,v) \in E\), then we say that e is an edge from u to v, and we sometimes denote this by \(u \rightarrow v\). In this case, we also say that u is an inneighbour of v and v is an outneighbour of u. The outneigbourhood of a vertex \(u \in V(G)\), denoted by \(N_\mathrm {o}^{G}({u})\), is the set of all outneighbours of u in G. The concept of inneighbourhood is defined analogously. An edge of the form (uu) is called a loop (on u) and sometimes denoted by .

A walk of length \(\ell \) from u to v in G is a sequence \(v_0, \dots , v_\ell \) of (not necessarily distinct) vertices such that \(v_0 = u\), \(v_\ell = v\), and there is an edge from each vertex to the next one (except for the last vertex, of course): \(v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_\ell \). If \(v_0 = v_\ell \), then we say that the walk is closed. A path (cycle) is a (closed) walk in which the vertices are pairwise distinct (with the exception of the first and last vertex in case of a cycle). A digraph without cycles is called acyclic.

We say that a vertex u is reachable from v if there exists a walk (equivalently, a path) from v to u. A pair of vertices u and v is said to be strongly connected if each one of u and v is reachable from the other. The relation of being strongly connected is an equivalence relation, and the induced subgraphs on its equivalence classes are called the strongly connected components of G. A digraph is strongly connected if it has just one strongly connected component. A one-vertex graph with no edge is strongly connected (let us call this the trivial strongly connected graph); apart from this trivial example, every vertex of a strongly connected digraph is contained in a cycle of nonzero length (this includes the graph of one vertex with a loop on it).

A digraph with a symmetric edge relation is called an undirected graph. The strongly connected components of an undirected graph are called connected components. The underlying undirected graph of a digraph \(G = (V,E)\) is the undirected graph \((V,E')\), where the edge relation \(E'\) equals the symmetric closure of E.

A tree is an undirected graph in which any two vertices are connected by exactly one path. A rooted directed tree is a directed acyclic graph whose underlying undirected graph is a tree and that has a distinguished vertex, called the root, from which all vertices are reachable. Let v be a vertex of a rooted directed tree T. Unless v is the root of T, it has a unique inneighbour, which is referred to as the parent of v. The outneighbours of v are called children of v. A childless vertex is called a leaf. The vertices reachable from v are called descendants of v, and v is called an ancestor of any of its descendants. The rooted induced subtree of T rooted at v, denoted by \(T_v\), is the subgraph of T induced by v and all its descendants.

The depth of a vertex v in a rooted directed tree T is the length of the (unique) path from the root to v, denoted by \(d_T(v)\). (Thus the root has depth 0.) The height of the tree T, denoted by h(T), is the maximum of the depths of its vertices: \(h(T) = \max \{d_T(v) \mid v \in V(T)\}\).

2.3 Graph algebras

Graph algebras were introduced by Shallon [17]. We associate any digraph \(G = (V,E)\) with an algebra \(\mathbb {A}({G}) = (V \cup \{\infty \}; {\circ }, \infty )\) of type (2, 0), where \(\infty \) is a new element distinct from the vertices, and the binary operation is defined by the following rule: for any \(x, y \in V \cup \{\infty \}\),

$$\begin{aligned} x \circ y := {\left\{ \begin{array}{ll} x, &{} \text {if }(x,y) \in E\text {,} \\ \infty , &{} \text {otherwise.} \end{array}\right. } \end{aligned}$$

The algebra \(\mathbb {A}({G})\) is called the graph algebra of G. Graph algebras provide a simple encoding of graphs as algebras, and using this encoding, the algebraic properties of the graph algebra \(\mathbb {A}({G})\) can be seen as properties of the graph G itself.

We are particularly interested in the satisfaction of identities by graph algebras. Recall that a term is, informally speaking, a well-formed string comprising variables and function symbols from the language of algebras under consideration. An identity is an ordered pair \((t,t')\) of terms, usually written as \(t \approx t'\). An algebra \({\mathbb {A}}\) satisfies an identity \(t \approx t'\) if for all assignments of values to the variables occurring in t and \(t'\), the two terms get the same value when the function symbols are interpreted as the fundamental operations of \({\mathbb {A}}\). An identity \(t \approx t'\) is trivial if \(t = t'\). Trivial identities are clearly satisfied by all algebras (of the given type). For further details, see, e.g., [9].

Let t be a term in the language of graph algebras. Denote by \({{\,\mathrm{var}\,}}(t)\) the set of variables occurring in t and by L(t) the leftmost variable occurring in t. We say that t is trivial if it contains an occurrence of the constant symbol \(\infty \); otherwise, t is nontrivial. Nontrivial terms are thus just groupoid terms. To any nontrivial term t, we can associate a digraph \(G(t) = (V,E)\), where \(V = {{\,\mathrm{var}\,}}(t)\), and \((x_i, x_j) \in E\) if and only if t has a subterm \((t_1 \circ t_2)\) with \(L(t_1) = x_i\) and \(L(t_2) = x_j\).

The following result is very helpful for determining whether a graph algebra satisfies an identity.

Proposition 2.1

(Pöschel, Wessel [16, Proposition 1.5(2)]) Let \(G = (V,E)\) be a digraph. Let t and \(t'\) be nontrivial terms in the language of graph algebras, and assume that \({{\,\mathrm{var}\,}}(t) = {{\,\mathrm{var}\,}}(t')\) and \(L(t) = L(t')\). Then the following conditions are equivalent:

  1. (i)

    \(\mathbb {A}({G})\) satisfies \(t \approx t'\);

  2. (ii)

    for every map \(\varphi :{{\,\mathrm{var}\,}}(t) \rightarrow V\), we have that \(\varphi \) is a homomorphism of G(t) into G if and only if \(\varphi \) is a homomorphism of \(G(t')\) into G.

2.4 Associative spectra

Let \(B_n\) denote the set of bracketings of size n, i.e., groupoid terms obtained from the string \(x_1 \cdot x_2 \cdot \ldots \cdot x_n\) by inserting parentheses appropriately. The number of bracketings of size n is given by the \((n-1)\)-st Catalan number \(C_{n-1} = \frac{1}{n} \left( {\begin{array}{c}2n-2\\ n-1\end{array}}\right) \). If \(\mathbb {A}= (A; {\cdot })\) is a groupoid, then the equational theory of \(\mathbb {A}\) induces an equivalence relation \(\sigma _n(\mathbb {A})\) on \(B_n\), i.e., \((t,t') \in \sigma _n(\mathbb {A})\) if and only if \(\mathbb {A}\) satisfies \(t \approx t'\). The sequence \(\{\sigma _n(\mathbb {A})\}_{n=1}^\infty \) is called the fine associative spectrum of \(\mathbb {A}\). The associative spectrum of \(\mathbb {A}\) is the sequence \(\{s_n(\mathbb {A})\}_{n=1}^\infty \) of natural numbers defined by \(s_n(\mathbb {A}) := |{B_n / \sigma _n(\mathbb {A})}|\). Equivalently, \(s_n(\mathbb {A})\) is the number of distinct term operations of \(\mathbb {A}\) induced by the bracketings of size n. Intuitively, the faster the associative spectrum grows, the less associative the operation is considered. A groupoid \(\mathbb {A}\) is a semigroup if and only if \(s_n(\mathbb {A}) = 1\) for all \(n \in \mathbb {N}\). On the other extreme, we have the antiassociative groupoids whose associative spectrum is given by the Catalan numbers: \(s_n(\mathbb {A}) = |{B_n}| = C_{n-1}\). These groupoids do not satisfy any nontrivial identity of the form \(t_1 \approx t_2\) with \(t_1, t_2 \in B_n\).

Since there exists only one bracketing of size 1, namely \(x_1\), and of size 2, namely \((x_1 x_2)\), it is clear that \(s_1(\mathbb {A}) = s_2(\mathbb {A}) = 1\) for every groupoid \(\mathbb {A}\). Therefore, we may always assume that \(n \ge 3\) when we consider bracketings of size n or the n-th component of an associative spectrum.

2.5 DFS trees

It turns out that the graphs associated with bracketings are particularly nice; they are rooted directed trees of a very special form.

Fig. 1
figure 1

The DFS tree of the bracketing \(((x_1((x_2x_3)x_4))x_5)(x_6(x_7x_8))\)

Definition 2.2

A DFS tree of size n is a rooted directed tree T on the vertex set \(X_n := \{x_1, x_2, \dots , x_n\}\) that has root \(x_1\) and for every vertex \(x_i \in X_n\), the induced subtree \(T_{x_i}\) has vertex set of the form \(X_{[i,i']} := \{x_j \mid j \in [i,i']\}\) for some \(i' \in [{n}]\) with \(i' \ge i\).

The name “DFS tree” stems from the fact that the vertices are labelled in an order in which they may be discovered by the depth-first search (DFS) (see [6, Section 22.3]) starting from the root. Figure 1 shows the DFS tree G(t) of size 8 that corresponds to the bracketing \(t=((x_1((x_2x_3)x_4))x_5)(x_6(x_7x_8))\). The dotted line shows the walk traversed by the depth-first search (using the convention that the search continues always with the leftmost unvisited child). Note that the order of first occurrence of the vertices along this walk is \(x_1,x_2,\dots ,x_8\).

Lemma 2.3

(cf. [6, Theorem 22.7 (Parenthesis theorem)]) Let T be a rooted directed tree on \(X_n\). The following are equivalent.

  1. (i)

    T is a DFS tree.

  2. (ii)

    The sequence \(x_1, x_2, \dots , x_n\) is a possible order in which the vertices of T may be traversed by the depth-first search starting from the root.

Proof

(i) \(\Rightarrow \) (ii): Assume that T satisfies condition (i). Condition (ii) will follow if we prove that for each vertex \(x_i \in X_n\), the vertices of the rooted induced subtree \(T_{x_i}\) (by our assumption \(V(T_{x_i}) = X_{[i,i']}\) for some \(i' \ge i\)) may be traversed by the depth-first search in the order \(x_i, x_{i+1}, \dots , x_{i'}\). We proceed by induction on the height of subtrees. The claim obviously holds for rooted induced subtrees of height 0. Assume that the claim holds for rooted induced subtrees of height at most k, and let \(x_i \in X_n\) be a vertex such that \(h(T_{x_i}) = k + 1\). Let \(x_{i_1}, x_{i_2}, \dots , x_{i_\ell }\) be the children of \(x_i\) in T with \(i_1< i_2< \dots < i_\ell \). By condition (i), for each \(s \in [{\ell }]\), \(V(T_{x_{i_s}}) = X_{[i_s, i'_s]}\) for some \(i'_s \ge i_s\); in fact \(i'_s = i_{s+1} - 1\) for \(1 \le s < \ell \), \(i_1 = i + 1\), and \(V(T_{x_i}) = X_{[i,i'_\ell ]}\). By the induction hypothesis, the vertices of \(T_{x_{i_s}}\) may be traversed by the depth-first search in the order \(x_{i_s}, x_{i_s + 1}, \dots , x_{i'_s}\); consequently, the vertices of \(T_{x_i}\) may be traversed in the order \(x_i, x_{i_1}, x_{i_1 + 1}, \dots , x_{i'_1}, x_{i_2}, x_{i_2 + 1}, \dots , x_{i'_2}, \dots , x_{i_\ell }, x_{i_\ell + 1}, \dots , x_{i'_\ell }\), that is, in the order \(x_i, x_{i+1}, \dots , x_{i'_\ell }\).

(ii) \(\Rightarrow \) (i): Assume that T satisfies condition (ii). For any \(x_i \in X_n\), \(x_i\) is the first vertex in \(T_{x_i}\) visited by the depth-first search, all vertices of \(T_{x_i}\) are traversed before the depth-first search continues with vertices not belonging to \(T_{x_i}\), and once the depth-first search leaves the subtree \(T_{x_i}\), it will never return to it. Consequently, condition (i) clearly holds. \(\square \)

It is a well-known fact that a digraph G is isomorphic to G(t) for some term t if and only if G is finite and rooted, i.e., there exists a vertex from which every vertex of G is reachable (see Kiss [13], Lemma 2). For the digraphs associated with bracketings, we obtain a sharper result: bracketings of size n are in a one-to-one correspondence with DFS trees of size n.

Lemma 2.4

Let \(n \in \mathbb {N}\).

  1. (a)

    For any bracketing \(t \in B_n\), the graph G(t) is a DFS tree of size n.

  2. (b)

    Conversely, for every DFS tree T of size n, there is a unique bracketing \(t \in B_n\) such that \(G(t) = T\).

Proof

(a) Let \(t \in B_n\). Then G(t) is a graph on \(X_n\) by definition. We will prove by induction on the structure of terms that for every subterm \(t'\) of t, the graph \(G(t')\) is a directed tree on \({{\,\mathrm{var}\,}}(t')\) with root \(L(t')\) such that for every \(x_i \in {{\,\mathrm{var}\,}}(t')\), the subtree of \(G(t')\) rooted at \(x_i\) has vertex set of the form \(X_{[i,i']}\) for some \(i' \in [{n}]\) with \(i' \ge i\). The claim obviously holds for any subterm of the form \(t' = x_i \in X_n\). Let now \(t' = (t_1 \circ t_2)\) and assume that the claim holds for the subterms \(t_1\) and \(t_2\). By the induction hypothesis, for \(\ell \in \{1,2\}\), \(G(t_\ell )\) is a directed tree on \({{\,\mathrm{var}\,}}(t_\ell )\) with root \(L(t_\ell )\); moreover, \({{\,\mathrm{var}\,}}(t_\ell ) = X_{[p_\ell , q_\ell ]}\), where \(p_\ell = L(t_\ell )\) and \(q_\ell \ge p_\ell \). In fact, \(q_1 = p_2 - 1\). Since \({{\,\mathrm{var}\,}}(t_1) \cap {{\,\mathrm{var}\,}}(t_2) = \emptyset \), \(G(t')\) is obtained by adding the edge \(L(t_1) \rightarrow L(t_2)\) to the disjoint union of \(G(t_1)\) and \(G(t_2)\); the resulting graph is a directed tree on \({{\,\mathrm{var}\,}}(t') = X_{[p_1, q_2]}\). Moreover, given a vertex \(x_i \in {{\,\mathrm{var}\,}}(t')\), we have that the subtree of \(G(t')\) induced by \(x_i\) is identical to the one induced by \(x_i\) in \(G(t_1)\) if \(x_i \in {{\,\mathrm{var}\,}}(t_1) \setminus \{x_{p_1}\}\) and identical to the one induced by \(x_i\) in \(G(t_2)\) if \(x_i \in {{\,\mathrm{var}\,}}(t_2)\); by the induction hypothesis, the subtree has the desired form.

(b) For the purpose of this proof, we relax the notions of bracketing and DFS tree so as to allow variable or vertex sets of the form \(X_{[a,b]}\). Let \(a, b \in \mathbb {N}\) with \(a \le b\), and let \(n := b - a + 1\). A term t with \({{\,\mathrm{var}\,}}(t) = X_{[a,b]}\) is an [ab]-bracketing if t can be obtained from some \(t' \in B_n\) by replacing each variable \(x_i\) by \(x_{a+i-1}\), \(1 \le i \le n\). Similarly, a rooted directed tree T on \(X_{[a,b]}\) is an [ab]-DFS tree if there is a DFS tree \(T'\) of size n such that the map \(x_i \mapsto x_{a+i-1}\) is an isomorphism \(T' \rightarrow T\).

We show that for any \(a, b \in \mathbb {N}\) with \(a \le b\), it holds that for every [ab]-DFS tree T, there exists a unique [ab]-bracketing t such that \(G(t) = T\). We proceed by induction on the length \(b-a\) of the interval [ab]. The claim is obvious for \(b - a = 0\), i.e., \(a = b\). Assume that the claim holds whenever \(b - a \le k\). Let now a and b be such that \(b - a = k + 1\), and let T be an [ab]-DFS tree. Let \(x_{i_1}, x_{i_2}, \dots , x_{i_\ell }\) be the children of the root vertex \(x_a\), and assume that \(i_1< i_2< \dots < i_\ell \). Then \(T - T_{x_{i_\ell }}\) is an \([a, i_\ell - 1]\)-DFS tree and \(T_{x_{i_\ell }}\) is an \([i_\ell , b]\)-DFS tree, so by the induction hypothesis there exist a unique \([a, i_\ell - 1]\)-bracketing r such that \(T - T_{x_{i_\ell }} = G(r)\) and a unique \([i_\ell , b]\)-bracketing s such that \(T_{x_{i_\ell }} = G(s)\). Then \(t := (r \circ s)\) is an [ab]-bracketing and it is easy to see that \(G(t) = T\) because \(L(r) = x_a\) and \(L(s) = x_{i_\ell }\). This proves existence. As for uniqueness, assume \(t'\) is another [ab]-bracketing such that \(G(t') = T\). Since \(x_a \rightarrow x_{i_\ell }\) is an edge in T, \(t'\) must contain a subterm of the form \((r' \circ s')\) where \(L(r') = x_a\), \(L(s') = x_{i_\ell }\). Then \({{\,\mathrm{var}\,}}(r') = X_{[a, i_\ell - 1]}\), so \(G(r')\) is the subtree of T with vertex set \(X_{[a, i_\ell - 1]}\), that is \(G(r') = T - T_{x_{i_\ell }} = G(r)\). Observe that \(t'\) contains no subterm of the form \((r' \circ s') \circ s''\) (otherwise \(L(s'') =: x_p\) would be a child of \(x_a\) with \(p > i_\ell \), contradicting the choice of \(i_\ell \)). Consequently \({{\,\mathrm{var}\,}}(s') = X_{[i_\ell , b]}\), so \(G(s') = T_{x_{i_\ell }} = G(s)\). By the induction hypothesis \(r = r'\) and \(s = s'\), so \(t = (r \circ s) = (r' \circ s') = t'\). \(\square \)

Proposition 2.5

DFS trees are uniquely determined by their depth sequences: if T and \(T'\) are DFS trees of size n such that \(d_T(x_i) = d_{T'}(x_i)\) for all \(i \in \{1, \dots , n\}\), then \(T = T'\).

Proof

Suppose, to the contrary, that DFS trees T and \(T'\) satisfy \(d_T(x_i) = d_{T'}(x_i)\) for all \(i \in \{1, \dots , n\}\) but \(T \ne T'\). Then there exists a vertex \(x_d \in X_n\) such that its parent \(x_p\) in T is distinct from its parent \(x_q\) in \(T'\). Assume without loss of generality that \(p < q\). Since \(d_T(x_d) = d_{T'}(x_d)\), we also have \(d_{T'}(x_p) = d_T(x_p) = d_T(x_d) - 1 = d_{T'}(x_d) - 1 = d_{T'}(x_q) = d_T(x_q)\). It follows from this that \(x_d \in T_{x_p}\) and \(x_q \notin T_{x_p}\); therefore, \(p< d < q\) by Definition 2.2. On the other hand, \(x_d \in T'_{x_q}\); therefore, \(q < d\). We have reached a contradiction. \(\square \)

A sequence \((d_1,\dots ,d_n)\) of nonnegative integers is called a zag sequenceFootnote 1 if

$$\begin{aligned} d_1=0,\ d_2=1,\text { and }1 \le d_{i+1} \le d_i + 1\text { for all } i\in \{1,\dots ,n-1\}. \end{aligned}$$
(1)

This notion was introduced in [7], where bracketings were represented by binary trees instead of DFS trees. (See also Exercise 19(u) in [18].) The depth of a vertex in a DFS tree is the same as the so-called “right depth” of the corresponding vertex in the binary tree representing the same bracketing. Therefore, 2.8 of [7] implies that depth sequences of DFS trees are in a one-to-one correspondence with zag sequences. We include an easy proof of this fact for the sake of self-containedness.

Proposition 2.6

A sequence \((d_1,\dots ,d_n)\) of nonnegative integers is the depth sequence of a DFS tree of size n if and only if it is a zag sequence.

Proof

Necessity is clear: if \(x_{i+1}\) is a child of \(x_i\) in a DFS tree T, then \(d_T(x_{i+1})=d_T(x_i)+1\); otherwise, \(x_{i+1}\) is a child of one of the ancestors of \(x_i\), hence \(d_T(x_{i+1}) \le d_T(x_i)\). We prove sufficiency by induction on n. The case \(n=1\) is trivial, so let \(n\ge 2\), and assume that every zag sequence of length less than n is the depth sequence of a DFS tree (which is unique, by Proposition 2.5). Let \((d_1,\dots ,d_n)\) be a zag sequence, and let \(d_k=1\) be the last occurrence of 1 in the sequence (possibly \(k=2\)). Then \(d_1,\dots ,d_{k-1}\) and \(d_k-1,\dots ,d_n-1\) are zag sequences of length less than n; hence, by our induction hypothesis, they are depth sequences of DFS trees \(T_1\) (of size \(k-1\)) and \(T_2\) (of size \(n-k+1\)), respectively. Let us form the disjoint union of \(T_1\) and \(T_2\) after applying the renaming \(x_i \mapsto x_{i+k-1}\) to the vertices of \(T_2\). Now if we add an edge from \(x_1\) (the root of \(T_1\)) to \(x_k\) (the new root of \(T_2\)), then we obtain a DFS tree of size n with depth sequence \((d_1,\dots ,d_n)\). \(\square \)

Fig. 2
figure 2

The zag sequence of the DFS tree T of Fig. 4

Remark 2.7

Zag sequences of length n can be visualized as lattice paths from the origin to the line \(x=n-1\) using steps \((1,1),(1,0),(1,-1),(1,-2),\dots \). Figure 2 depicts the lattice path of the zag sequence (0, 1, 2, 3, 3, 4, 4, 1, 2, 1, 2, 3, 2, 3, 3) corresponding to the DFS tree T shown on the left-hand side of Fig. 4.

Another family of lattice paths is also closely related to bracketings and DFS trees. A Dyck path of semilength n is a lattice path from (0, 0) to (2n, 0) consisting of n up-steps \(U=(1,1)\) and n down-steps \(D=(1,-1)\) in such a way that the path never goes below the x-axis. To construct the Dyck path corresponding to a DFS tree T, let us draw T in such a way that all edges point upwards, and the children of every vertex are drawn in increasing order (of their subscripts) from left to right. (All DFS trees in this paper are drawn using this convention.) Let us follow the depth-first search on T, including the backtracking steps, returning to the root in the end (see the dotted line in Fig. 1). For each step, we add an up-step U or a down-step D to our lattice path starting at the origin according to whether we are moving upwards or downwards in the tree. (See Fig. 3 for the Dyck path corresponding to the DFS tree of Fig. 1. The first occurrence of each vertex during the depth-first search is labelled on the diagram.) This way we obtain a bijection from the set of DFS trees of size n to the set of Dyck paths of semilength \(n-1\). A wormderful explanation of this bijection is presented in [19, p. 10], where this process is actually used to define the depth-first order.

Fig. 3
figure 3

The Dyck path of the DFS tree of Fig. 1

2.6 Collapsing maps and a few lemmas

Definition 2.8

Let T be a DFS tree of size n, and let G be a digraph. If \(h := h(T)\) and \(W :v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_h\) is a walk in G, then the mapping \(\varphi :X_n \rightarrow V(G)\), \(x_i \mapsto v_{d_T(x_i)}\) is clearly a homomorphism of T into G. Similarly, if \(C :u_0 \rightarrow u_1 \rightarrow \dots \rightarrow u_{\ell - 1} \rightarrow u_0\) is a closed walk in G with \(\ell \ge 1\), then the mapping \(\psi :X_n \rightarrow V(G)\), \(x_i \mapsto v_{d_T(x_i) \bmod \ell }\) is a homomorphism of T into G. Such homomorphisms \(\varphi \) and \(\psi \) are referred to as collapsing maps of T on W and C, respectively, and we say that the DFS tree T is collapsed on the walk W (on the closed walk C) by \(\varphi \) (by \(\psi \)).

We will often specify homomorphisms of DFS trees by giving a piecewise definition in which each piece is a collapsing map of a subgraph. In particular, if T is a DFS tree of size n, \(x_d \in X_n\), \(s := d_T(x_d) > 0\), \(h := h(T)\), \(h' := h(T_{x_d})\), \(W :v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_s \rightarrow \dots \rightarrow v_h\) is a walk in G, \(v_{s-1} \rightarrow u_0\) is an edge, and \(W'\) is either a walk \(u_0 \rightarrow u_1 \rightarrow \dots \rightarrow u_{h'}\) or a closed walk \(u_0 \rightarrow u_1 \rightarrow \dots \rightarrow u_\ell \rightarrow u_0\), then the mapping \(\varphi :X_n \rightarrow V(G)\) that collapses \(T \setminus T_{x_d}\) on W and \(T_{x_d}\) on \(W'\) is a homomorphism of T into G, and we will refer to \(\varphi \) as the collapsing map of \((T,x_d)\) on \((W,W')\), and we say that \((T,x_d)\) is collapsed on \((W,W')\) by \(\varphi \).

Example 2.9

Figure 4 shows a collapsing map \(\varphi \) of \((T,x_{13})\) on \((W,W')\), where \(W :v_0 \rightarrow v_1 \rightarrow v_2 \rightarrow v_3 \rightarrow v_4\) and \(W' :u_0 \rightarrow u_1\) are walks in a graph G and T is a DFS tree of size 15. Each vertex of T is mapped to the vertex on the same level in G represented by the same type of node (filled or empty).

Fig. 4
figure 4

Collapsing \((T,x_{13})\) on \((W,W')\)

With the help of collapsing maps and Proposition 2.1, we can derive conditions for the edges of a digraph satisfying a bracketing identity. Let us illustrate this with a few examples that will serve as helpful tools later.

Lemma 2.10

Let \(t, t' \in B_n\), \(t \ne t'\), \(T := G(t)\), \(T' := G(t')\), \(h := h(T)\), and let G be a digraph such that \(\mathbb {A}({G})\) satisfies the identity \(t \approx t'\). If \(W :v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_h\) is a walk in G, then \((v_{d_T(a)}, v_{d_T(b)}) \in E(G)\) for every \((a,b) \in E(T')\).

Proof

The collapsing map \(\varphi \) of T on W is a homomorphism of T into G, so it is also a homomorphism of \(T'\) into G by Proposition 2.1. Consequently, for every edge (ab) of \(T'\), we have \((v_{d_T(a)}, v_{d_T(b)}) = (\varphi (a), \varphi (b)) \in E(G)\). \(\square \)

Lemma 2.11

Let \(t, t' \in B_n\), \(t \ne t'\), \(T := G(t)\), \(T' := G(t')\), and let G be a digraph such that \(\mathbb {A}({G})\) satisfies the identity \(t \approx t'\). Then the following statements hold.

  1. (a)

    If \(u, v \in V(G)\), \(\{(u,u), (u,v)\} \subseteq E(G)\), and G contains arbitrarily long walks with initial vertex v, then \(\{(v,u), (v,v)\} \subseteq E(G)\).

  2. (b)

    If \(u, v, w \in V(G)\) and \(\{(u,u), (v,v), (w,w), (v,u), (v,w)\} \subseteq E(G)\), then \(\{(u,w), (w,u)\} \subseteq E(G)\).

  3. (c)

    If \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {2}\) for all \(x_i \in X_n\), \(u, v, w \in V(G)\), \(\{(u,v), (v,u), (v,w)\} \subseteq E(G)\) and G contains arbitrarily long walks with initial vertex w, then \((w,v) \in E(G)\).

  4. (d)

    If \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {2}\) for all \(x_i \in X_n\), \(u, v, u', v' \in V(G)\), \(\{(u,v), (v,u), (u,v'), (v',u), (v,u'), (u',v)\} \subseteq E(G)\), then \(\{(u',v'), (v',u')\} \subseteq E(G)\).

Proof

Since \(t \ne t'\), there exists a vertex \(x_d\) that has distinct parents in T and \(T'\), say \(x_p\) and \(x_q\), respectively. We have \(p < d\) and \(q < d\), and, changing the roles of T and \(T'\) if necessary, we may assume that \(p< q < d\). By Definition 2.2, \(x_q, x_d \in V(T_{x_p})\) but \(x_q \notin V(T_{x_d})\). Let \(h := h(T)\), \(s := d_T(x_d)\), \(r := d_T(x_q)\). Note that \(d_T(x_p) = s-1\) and \(r \ge s\).

For each statement, we are going to provide suitable walks \(W :v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_h\) and \(W' :u_0 \rightarrow u_1 \rightarrow \cdots \) in G, with \(v_{s-1} \rightarrow u_0\) being an edge, and we consider the collapsing map \(\varphi \) of \((T,x_d)\) on \((W,W')\), which is a homomorphism of T into G. By Proposition 2.1, \(\varphi \) is also a homomorphism of \(T'\) into G. Since \((x_q, x_d) \in E(T')\), we obtain the desired edge \((\varphi (x_q), \varphi (x_d)) = (v_r, u_0) \in E(G)\).

(a) We obtain the edge \(v \rightarrow u\) by letting W be the walk starting with r occurrences of u, followed by a walk of length \(h-r\) starting at v, and letting \(W'\) be the cycle \(u \rightarrow u\). We obtain the edge \(v \rightarrow v\) by letting W be as above and letting \(W'\) be a sufficiently long walk starting at v.

(b) We obtain the edge \(u \rightarrow w\) by letting \(W :v \rightarrow \dots \rightarrow v \rightarrow u \rightarrow \dots \rightarrow u\) with r occurrences of v and \(h-r+1\) occurrences of u and \(W' :w \rightarrow w\). By swapping u with w in the above, we obtain also the edge \(w \rightarrow u\).

(c) We obtain the edge \(w \rightarrow v\) by letting \(W :v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_h\) be the walk in which \(v_0, \dots , v_{r-1}\) alternate between vertices u and v such that \(v_{r-1} = v\), followed by the vertices of a walk of length \(h-r\) starting at w, and letting \(W'\) be the cycle \(v \rightarrow u \rightarrow v\). Note that \(s-1 = d_T(x_p) = d_T(x_d) - 1 \equiv d_{T'}(x_d) - 1 = d_{T'}(x_q) \equiv d_T(x_q) = r \pmod {2}\), so \(v_{s-1} = u\) and \(v_{s-1} \rightarrow u_0\) is indeed an edge in G.

(d) We obtain the edge \(u' \rightarrow v'\) by letting \(W :v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_h\) be the walk with \(v_i := u\) when \(i \equiv r \pmod {2}\) and \(i \ne r\), \(v_r := u'\), and \(v_i := v\) when \(i \not \equiv r \pmod {2}\), and letting \(W'\) be the cycle \(v' \rightarrow u \rightarrow v'\). Note that we have \(s-1 \equiv r \pmod {2}\) as above, so \(v_{s-1} = u\) and \(v_{s-1} \rightarrow u_0\) is indeed an edge in G. Switching the roles of u and v, while also switching the roles of \(u'\) and \(v'\), yields \(v' \rightarrow u'\). \(\square \)

Remark 2.12

There exist arbitrarily long walks with initial vertex v if, for example, v lies on a cycle, or there is a path from v to a vertex \(v'\) that lies on a cycle.

3 Associative spectra of graph algebras of undirected graphs

It is relatively easy to determine the associative spectra of graph algebras of undirected graphs. It turns out that there are only three distinct possibilities: the sequences of all 1’s, powers of 2, and Catalan numbers. Undirected graphs are classified into these three types in Theorem 3.3.

As we will see, a key criterion for the classification of pairs of distinct DFS trees of size n is whether the depths of each vertex in the two trees are congruent modulo 2.

Lemma 3.1

Let \(\sim \) be the equivalence relation on \(B_n\) that relates t and \(t'\) if and only if \(d_{G(t)}(x_i) \equiv d_{G(t')}(x_i) \pmod {2}\) for all \(x_i \in X_n\). Then \(|{B_n / {\sim }}| = 2^{n-2}\) for \(n \ge 2\).

Proof

Let us define the depth sequence modulo 2 of a bracketing \(t \in B_n\) as the tuple \(d_{t,2} := (d_1, d_2, \dots , d_n)\), where \(d_i := d_{G(t)}(x_i) \bmod {2}\). Obviously, it holds that \(d_{t,2} \in \{0\} \times \{1\} \times \{0,1\}^{n-2}\), because the vertices \(x_1\) and \(x_2\) always have depths 0 and 1 in G(t), respectively. On the other hand, every tuple \((d_1, d_2, \dots , d_n) \in \{0\} \times \{1\} \times \{0,1\}^{n-2}\) is the depth sequence modulo 2 of some bracketing \(t \in B_n\), which we can build as follows. The vertices \(x_1\) and \(x_2\) must have depths 0 and 1, respectively. For \(j = 2, \dots , n\), if \(d_j \ne d_{j-1}\), then we add \(x_j\) as a child of \(x_{j-1}\); if \(d_j = d_{j-1}\), then we add \(x_j\) as a child of the unique parent of \(x_{j-1}\). It is now obvious that \(|{B_n / {\sim }}| = |{\{0\} \times \{1\} \times \{0,1\}^{n-2}}| = 2^{n-2}\). \(\square \)

Lemma 3.2

Let K be an undirected connected graph with no loops. Assume that for all vertices a, b, c, d of K it holds that if \(a \rightarrow b \rightarrow c \rightarrow d\) is a walk in K, then \(a \rightarrow d\) is an edge. Then K is complete bipartite.

Proof

Suppose, to the contrary, that K is not bipartite. Then K has a cycle of odd length \(m \ge 3\), say \(v_1 \rightarrow v_2 \rightarrow \dots \rightarrow v_m \rightarrow v_1\). By applying our assumption to the walk \(v_{m-2} \rightarrow v_{m-1} \rightarrow v_m \rightarrow v_1\), we get the edge \(v_{m-2} \rightarrow v_1\); hence, \(v_1 \rightarrow v_2 \rightarrow \dots \rightarrow v_{m-2} \rightarrow v_1\) is a cycle of length \(m-2\) in K. Repeating this argument, we eventually arrive at a cycle of length 1. This contradicts the fact that K has no loops.

We have established that K must be bipartite. It remains to show that K is complete bipartite. Let \(B_1\), \(B_2\) be a bipartition of K, and let \(x \in B_1\), \(y \in B_2\). We want to show that \(x \rightarrow y\) is an edge in K. Since K is connected, there exists a path \(x = v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_n = y\) in K, with n odd. If \(n \ge 3\), then our assumption implies that \(v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_{n-3} \rightarrow v_n\) is a path of length \(n-2\) from x to y. Repeating this argument, we eventually get a path of length 1 from x to y, i.e., an edge \(x \rightarrow y\). \(\square \)

Theorem 3.3

Let G be an undirected graph.

  1. (i)

    If every connected component of G is either trivial or a complete graph (with loops), then \(\mathbb {A}({G})\) satisfies every bracketing identity. In this case, \(s_n(\mathbb {A}({G})) = 1\) for all \(n \in \mathbb {N}_+\).

  2. (ii)

    If every connected component is either trivial, a complete graph (with loops), or a complete bipartite graph, and the last case occurs at least once, then \(\mathbb {A}({G})\) satisfies a bracketing identity \(t \approx t'\) if and only if \(d_{G(t)}(x_i) \equiv d_{G(t')}(x_i) \pmod {2}\) for all \(x_i \in X_n\). In this case, \(s_n(\mathbb {A}({G})) = 2^{n-2}\) for all \(n \ge 2\).

  3. (iii)

    Otherwise \(\mathbb {A}({G})\) satisfies no nontrivial bracketing identity. In this case, \(s_n(\mathbb {A}({G})) = C_{n-1}\) for all \(n \in \mathbb {N}_+\).

Proof

Let \(t, t' \in B_n\), \(t \ne t'\). Denote \(T := G(t)\), \(T' := G(t')\). Assume that \(G = (V,E)\) satisfies \(t \approx t'\).

Claim 3.3.1

Every connected component of G containing a loop is a complete graph (with loops).

Proof

Let K be a connected component of G containing a loop. We will show that the edge relation E(K) is reflexive, symmetric, and transitive. From this, we can conclude that K is a complete graph with loops. The claim is obvious if K has only one vertex, so we may assume that K has at least two vertices. The edge relation is symmetric because G is undirected.

For reflexivity, let u be a vertex in K with a loop, and let v be a vertex adjacent to u. It follows from Lemma 2.11(a) that \((v,v) \in E(K)\) (note that v belongs to the cycle \(v \rightarrow u \rightarrow v\)). From this, we can conclude that every vertex in K has a loop, that is, the edge relation E(K) is reflexive.

For transitivity, assume that (uv) and (vw) are edges in K. By reflexivity, we have loops at vertices u, v and w, and by symmetry, we have also the edges (vu) and (wv). Now Lemma 2.11(b) implies that \((u,w) \in E(K)\). \(\square _{\mathrm{Claim 3.3.1}}\)

Claim 3.3.2

Every nontrivial connected component of G without loops is a complete bipartite graph. Such a component exists only if \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {2}\) for all \(x_i \in X_n\).

Proof

Let K be a nontrivial connected component of G without loops. Then K contains an edge (uv). Then the map \(\varphi :X_n \rightarrow V\),

$$\begin{aligned} \varphi (x) = {\left\{ \begin{array}{ll} u, &{} \text {if }d_T(x) \equiv 0 \pmod {2}\text {,} \\ v, &{} \text {if }d_T(x) \equiv 1 \pmod {2}\text {,} \end{array}\right. } \end{aligned}$$

is clearly a homomorphism of T into G. By Proposition 2.1, \(\varphi \) is a homomorphism of \(T'\) into G, so \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {2}\) for all \(x_i \in X_n\).

In order to conclude that K is complete bipartite, it suffices, by Lemma 3.2, to show that if \(a \rightarrow b \rightarrow c \rightarrow d\) is a walk in K, then (ad) is an edge. Since the edge relation is symmetric, this holds by Lemma 2.11(d). \(\square _{\mathrm{Claim 3.3.2}}\)

Proof of Theorem 3.3 continued

Claims 3.3.1 and 3.3.2 show that if G satisfies \(t \approx t'\), then the connected components of G are trivial, complete graphs (with loops), or complete bipartite graphs, and if the last case occurs, then \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {2}\) for all \(x_i \in X_n\).

Assume now that the connected components of G are trivial, complete graphs (with loops), or complete bipartite graphs, and if one of the components is a complete bipartite graph, then \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {2}\) for all \(x_i \in X_n\). In order to prove that G satisfies \(t \approx t'\), we apply Proposition 2.1. Let \(\varphi :X_n \rightarrow V\) be a homomorphism of T into G. Since T is connected and contains an edge, the image of \(\varphi \) lies in a single nontrivial connected component K of G. If K is a complete graph, then \(\varphi \) is obviously a homomorphism of \(T'\) into G.

Consider then the case where K is a complete bipartite graph with bipartition \(B_1, B_2\). It is easy to see that for all \(x_i, x_j \in X_n\), \(\varphi (x_i)\) and \(\varphi (x_j)\) lie in the same part (\(B_1\) or \(B_2\)) if and only if \(d_T(x_i) \equiv d_T(x_j) \pmod {2}\). By our assumption, we have \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {2}\) for all \(x_i \in X_n\), which implies that \(\varphi \) is also a homomorphism of \(T'\) into G.

A similar argument shows that every homomorphism of \(T'\) into G is also a homomorphism of T into G. By Proposition 2.1, G satisfies \(t \approx t'\).

We have shown that G satisfies a nontrivial bracketing identity \(t \approx t'\) if and only if the connected components of G are trivial, complete graphs (with loops), or complete bipartite graphs, and if the last case occurs, then \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {2}\) for all \(x_i \in X_n\). This gives us the three possible associative spectra. If \(\mathbb {A}({G})\) satisfies all bracketing identities, then \(\mathbb {A}({G})\) is associative and \(s_n(\mathbb {A}({G})) = 1\) for all \(n \in \mathbb {N}_+\). If \(\mathbb {A}({G})\) satisfies no nontrivial bracketing identity, then \(s_n(\mathbb {A}({G})) = C_{n-1}\) for all \(n \in \mathbb {N}_+\). In the last possible case, \(\sigma _n(\mathbb {A}({G}))\) relates t and \(t'\) if and only if \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {2}\) for all \(x_i \in X_n\); by Lemma 3.1 we have \(s_n(\mathbb {A}({G})) = 2^{n-2}\). \(\square \)

4 Associative and antiassociative digraphs

A digraph G is associative if \(\mathbb {A}({G})\) satisfies the associative identity \(x_1 (x_2 x_3) \approx (x_1 x_2) x_3\), i.e., if the associative spectrum of \(\mathbb {A}({G})\) is constant 1. Associative digraphs were characterized by Poomsa-ard [15]; the equivalence of conditions (i) and (ii) in the following can be verified by applying Proposition 2.1 to the DFS trees associated with the two bracketings appearing in the associative law (see Fig. 5).

Fig. 5
figure 5

Graphs associated with the terms of the associative identity \(t \approx t'\) with \(t := x_1 (x_2 x_3)\), \(t' := (x_1 x_2) x_3\)

Proposition 4.1

(Poomsa-ard [15, Proposition 2.2]) For any digraph \(G = (V,E)\), the following statements are equivalent.

  1. (i)

    G is associative.

  2. (ii)

    For any edge \((u,v) \in E\) and any vertex \(w \in V\), \((u,w) \in E\) if and only if \((v,w) \in E\).

  3. (iii)

    The edge relation E is transitive and for every \(v \in V\), the subgraph induced on the outneighbourhood \(N_\mathrm {o}^{G}({v})\) is a complete graph.

On the other extreme, we have the antiassociative digraphs whose graph algebras satisfy no nontrivial bracketing identities, i.e., the associative spectrum of \(\mathbb {A}({G})\) consists of the Catalan numbers. The goal of this section is to characterize antiassociative digraphs. To this end, we introduce some numerical parameters of bracketing identities in terms of the corresponding DFS trees, and we prove several necessary conditions for a graph algebra to satisfy a given bracketing identity.

Definition 4.2

Let \(t, t' \in B_n\), \(t \ne t'\), and let \(T := G(t)\), \(T' := G(t')\).

  1. (i)

    Let \(H_{t,t'}:= \min \{h(T), h(T')\}\).

  2. (ii)

    Let \(M_{t,t'}\) be the largest integer m such that \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {m}\) for all \(x_i \in X_n\). In other words, the depth sequences of T and \(T'\) are congruent modulo \(M_{t,t'}\).

  3. (iii)

    Let \(L_{t,t'}\) be the largest integer m such that for all \(x_i \in X_n\),

    $$\begin{aligned} \bigl ( d_T(x_i) \le m \vee d_{T'}(x_i) \le m \bigr ) \implies d_T(x_i) = d_{T'}(x_i). \end{aligned}$$

    In other words, the DFS trees T and \(T'\) are identical up to level \(L_{t,t'}\).

Note that \(0 \le H_{t,t'}< n\) (with \(H_{t,t'}= 0\) if and only if \(n = 1\)), \(0 \le L_{t,t'}< H_{t,t'}\) and \(1 \le M_{t,t'}\le H_{t,t'}\).

Example 4.3

Figure 6 shows two DFS trees corresponding to certain terms \(t, t' \in B_{20}\). It is straightforward to verify that \(H_{t,t'}= 6\), \(M_{t,t'}= 3\), and \(L_{t,t'}= 2\).

Fig. 6
figure 6

DFS trees with \(H_{t,t'}= 6\), \(M_{t,t'}= 3\), \(L_{t,t'}= 2\)

Lemma 4.4

Let \(t, t' \in B_n\), \(t \ne t'\), and let G be a digraph such that \(\mathbb {A}({G})\) satisfies the identity \(t \approx t'\). Denote \(H := H_{t,t'}\), \(M := M_{t,t'}\), \(L := L_{t,t'}\). Then there exists an integer r with \(L + 1 \le r \le H\) and \(r \equiv L \pmod {M}\) such that the following holds: if \(v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_H\) is a walk in G, then \(v_r \rightarrow v_{L+1}\) is an edge in G. In particular, \(v_{L+1}\) belongs to a nontrivial strongly connected component.

Proof

By the definition of L, there exists a vertex \(x_d \in X_n\) such that either \(d_T(x_d) = L + 1 < d_{T'}(x_d)\) or \(d_{T'}(x_d) = L + 1 < d_T(x_d)\). By changing the roles of T and \(T'\), if necessary, we may assume that \(d_T(x_d) = L + 1 < d_{T'}(x_d)\). Let \(x_p\) be the parent of \(x_d\) in T, and let \(x_q\) be the parent of \(x_d\) in \(T'\). Then \(d_T(x_p) = L\), and it follows from Definition 2.2 that \(V(T_{x_p}) = V(T'_{x_p})\) because the trees T and \(T'\) are identical up to level L. Since \(x_d \in V(T_{x_p}) = V(T'_{x_p})\) and \(d_{T'}(x_d) > L + 1\), we have \(x_q \in V(T'_{x_p}) = V(T_{x_p})\) and \(d_{T'}(x_q) = d_{T'}(x_d) - 1 \ge L+1\), so \(x_q \ne x_p\); hence, \(d_T(x_q) \ge L + 1\). Furthermore, by the definition of M, it holds that \(d_T(x_q) \equiv d_{T'}(x_q) = d_{T'}(x_d) - 1 \equiv d_T(x_d) - 1 = L \pmod {M}\).

Write \(h := h(T)\), \(h' := h(T')\), and consider first the case that \(h \le h'\), so \(h = H\). In this case, the statement of the Lemma holds with \(r := d_T(x_q)\), because \(L+1 \le r = d_T(x_q) \le h = H\) and \(r = d_T(x_q) \equiv L \pmod {M}\), and by Lemma 2.10, it holds that if \(v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_H\) is a walk in G, then \((v_{d_T(x_q)}, v_{d_T(x_d)}) = (v_r, v_{L+1}) \in E(G)\).

Consider now the case that \(h > h'\), so \(h' = H\). Let \(u_0 \rightarrow u_1 \rightarrow \dots \rightarrow u_h\) be a longest path in T, and write \(d_i := d_{T'}(u_i)\) for \(i \in \{0, \dots , h\}\). Now, since \(h > h'\), the sequence \(d_0, d_1, \dots , d_h\) cannot be strictly increasing, so there exists an index j with \(d_j \ge d_{j+1}\). Note that \(d_{j+1} \ge L+1\), because the trees T and \(T'\) are identical up to level L.

Assume that \(W :v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_H\) is a walk in G. By Lemma 2.10, \((v_{d_j}, v_{d_{j+1}}) \in E(G)\); consequently \(C :v_{d_{j+1}} \rightarrow v_{d_{j+1} + 1} \rightarrow \dots \rightarrow v_{d_j} \rightarrow v_{d_{j+1}}\) is a closed walk in G. Now, let \(W'\) be the walk in G that starts with \(v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_{d_{j+1}}\), and then, it continues around the closed walk C until it reaches length h. More precisely, \(W'\) is the walk \(v'_0 \rightarrow v'_1 \rightarrow \dots \rightarrow v'_h\) with \(v'_i := v_{i^*}\), where \(i^*\) is the largest integer m such that \(m \le \min (i, d_j)\) and \(m \equiv i \pmod {D}\), where \(D := d_j - d_{j+1} + 1\). By Lemma 2.10, \((v'_{d_T(x_q)}, v'_{d_T(x_d)}) = (v_r, v_{L+1}) \in E(G)\), where \(r := (d_T(x_q))^*\). By definition, we have \(L + 1 \le r \le d_j \le h' = H\) and \(r \equiv d_T(x_q) \pmod {D}\). Furthermore,

$$\begin{aligned} D = d_{T'}(u_j) - d_{T'}(u_{j+1}) + 1 \equiv d_T(u_j) - d_T(u_{j+1}) + 1 = 0 \pmod {M}, \end{aligned}$$

so M divides D (notation: \(M \big |D\)), and it follows that \(r \equiv d_T(x_q) \equiv L \pmod {M}\).

Now we have a closed walk \(v_{L+1} \rightarrow \dots \rightarrow v_r \rightarrow v_{L+1}\) in G. This means, in particular, that \(v_{L+1}\) belongs to a nontrivial strongly connected component. \(\square \)

The next lemma generalizes Lemma 2.11(a).

Lemma 4.5

Let \(t, t' \in B_n\), \(t \ne t'\), and let G be a digraph such that \(\mathbb {A}({G})\) satisfies the identity \(t \approx t'\). Denote \(H := H_{t,t'}\), \(M := M_{t,t'}\), \(L := L_{t,t'}\). If m is a divisor of M, \(U :u_0 \rightarrow u_1 \rightarrow \dots \rightarrow u_{m-1} \rightarrow u_0\) is a closed walk in G, \(u_0 \rightarrow w\) is an edge, and G contains arbitrarily long walks with initial vertex w, then \(w \rightarrow u_2\) if \(m > 2\) and \(w \rightarrow u_0\) if \(1 \le m \le 2\).

Proof

For \(m = 1\) this is Lemma 2.11(a). Assume that \(m \ge 2\). Let r be the number provided by Lemma 4.4, and let \(v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_H\) be a walk that starts by going around the closed walk U so that \(v_{r-1} = u_0\) (i.e., \(v_i := u_{i - r + 1 \bmod m}\) for \(0 \le i \le r-1\)) and continues with a walk of length \(H-r\) with initial vertex w. By Lemma 4.4, \(v_r \rightarrow v_{L+1}\) is an edge. We have \(v_r = w\) and \(v_{L+1} = u_{L + 1 - r + 1 \bmod m}\). Since \(r \equiv L \pmod {M}\) and \(m \big |M\), we have \(r \equiv L \pmod {m}\); hence \(L + 1 - r + 1 \equiv 2 \mod m\). Therefore \(w \rightarrow u_2\) is an edge if \(m > 2\) and \(w \rightarrow u_0\) is an edge if \(m = 2\). \(\square \)

For \(m \in \mathbb {N}_+\), the directed m-cycle is the digraph \(\mathsf {C}_{m}\) with \(V(\mathsf {C}_{m}) = \mathbb {Z}_m := [0,m-1]\) and \(E(\mathsf {C}_{m}) = \{(i,j) \in \mathbb {Z}_m \times \mathbb {Z}_m \mid j \equiv i + 1 \pmod {m} \}\).

Lemma 4.6

Let \(t, t' \in B_n\), \(t \ne t'\). Then for every \(m \in \mathbb {N}_+\), the directed m-cycle \(\mathsf {C}_{m}\) satisfies \(t \approx t'\) if and only if m is a divisor of \(M_{t,t'}\).

Proof

Denote \(M := M_{t,t'}\). Assume first that \(m \big |M\). By the definition of M, we have \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {M}\) for all \(x_i \in X_n\). Since \(m \big |M\), this implies \(d_T(x_i) \equiv d_{T'}(x_i) \pmod {m}\) for all \(x_i \in X_n\). Let \(\varphi :T \rightarrow \mathsf {C}_{m}\) be a homomorphism. Then \(\varphi \) is necessarily of the form \(x_i \mapsto (d_T(x_i) + k) \bmod {m}\) for some fixed \(k \in \mathbb {Z}_m\) (that is, \(\varphi \) collapses T onto \(\mathsf {C}_{m}\)). Then for every edge \((x_i, x_j)\) of \(T'\), we have

$$\begin{aligned}&\varphi (x_j) \equiv d_T(x_j) + k \equiv d_{T'}(x_j) + k = d_{T'}(x_i) + 1 + k \\&\quad \equiv d_T(x_i) + k + 1 \equiv \varphi (x_i) + 1 \pmod {m}, \end{aligned}$$

so \((\varphi (x_i), \varphi (x_j))\) is an edge of \(\mathsf {C}_{m}\). Therefore \(\varphi \) is a homomorphism of \(T'\) into \(\mathsf {C}_{m}\). A similar argument shows that every homomorphism \(\varphi :T' \rightarrow \mathsf {C}_{m}\) is a homomorphism \(T \rightarrow \mathsf {C}_{m}\). By Proposition 2.1, \(\mathsf {C}_{m}\) satisfies \(t \approx t'\).

Assume now that \(\mathsf {C}_{m}\) satisfies \(t \approx t'\). Let \(\varphi :T \rightarrow \mathsf {C}_{m}\) be the collapsing map of T on \(\mathsf {C}_{m}\) with \(\varphi (x_i) = d_T(x_i) \bmod {m}\). By Proposition 2.1, \(\varphi \) is a homomorphism \(T' \rightarrow \mathsf {C}_{m}\). Since the only homomorphisms of \(T'\) to \(\mathsf {C}_{m}\) are collapsing maps \(x_i \mapsto (d_{T'}(x_i) + k) \bmod m\) for some \(k \in \mathbb {Z}_m\), and since \(\varphi (x_1) = d_T(x_1) = 0 = d_{T'}(x_1)\), it follows that \(d_{T'}(x_i) \equiv d_T(x_i) \pmod {m}\) for all \(x_i \in X_n\). From the definition of M, it follows that \(m \big |M\). \(\square \)

Definition 4.7

A digraph \(G = (V,E)\) is called an m-whirl (\(m \in \mathbb {N}_+\)), if there exists a partition \(\{B_0, \dots , B_{m-1}\}\) of V such that for all \(x, y \in V\), \((x,y) \in E\) if and only if \(x \in B_i\) and \(y \in B_{i+1}\) for some \(i \in \{0, \dots , m-1\}\) (addition modulo m). The sets \(B_i\) are referred to as the blocks of G. We say that blocks \(B_i\) and \(B_j\) are consecutive if \(j \equiv i + 1 \pmod {m}\); then, \(B_i\) is called the predecessor of \(B_j\) and \(B_j\) is called the successor of \(B_i\). A digraph is called a whirl if it is an m-whirl for some \(m \in \mathbb {N}_+\).

In other words, an m-whirl G is a strong homomorphic preimage of the directed m-cycle \(\mathsf {C}_{m}\). By definition, 1-whirls are precisely the complete graphs with loops and 2-whirls are precisely the complete bipartite graphs. (Note the role of 1-whirls and 2-whirls in Theorem 3.3.)

Lemma 4.8

Let \(t, t' \in B_n\), \(t \ne t'\), and let G be a digraph such that \(\mathbb {A}({G})\) satisfies the identity \(t \approx t'\). Then every strongly connected component of G is either trivial or an m-whirl for some divisor m of \(M_{t,t'}\).

Proof

Let K be a nontrivial strongly connected component of G. Every vertex of K lies on a cycle contained in K; let C be a shortest cycle in K, and assume that C has length m. Lemma 4.6 implies that m is a divisor of \(M_{t,t'}\). We want to show that K is an m-whirl.

Assume first that \(m = 1\). Then K contains a vertex u with a loop. Let v be an arbitrary vertex of K. By strong connectivity, there exists a path from u to v. Since every vertex is contained in a cycle (again by strong connectivity), we can deduce with the help of Lemma 2.11(a) that every vertex along the path from u to v has a loop. We conclude that the edge relation of K is reflexive. The reflexivity of the edge relation and Lemma 2.11(a) imply immediately that the edge relation is symmetric. Now Lemma 2.11(b) implies in turn that the edge relation is transitive. We conclude that K is a complete graph with loops, i.e., a 1-whirl.

Assume now that \(m = 2\). Then \(M_{t,t'}\) is even, K contains no loop, and there is a cycle of length 2 in K, i.e., vertices u, v with \((u,v), (v,u) \in E(G)\). With the help of strong connectivity and Lemma 2.11(c), we can deduce that K is undirected. It now follows from Lemmas 3.2 and 2.11(d) that K is a complete bipartite graph, i.e., a 2-whirl.

From now on, assume that \(m > 2\). For notational simplicity, suppose that \(C = \mathsf {C}_{m}\), that is, \(V(C) = \mathbb {Z}_m\) and for all \(i, j \in \mathbb {Z}_m\), \(i \rightarrow j\) is an edge if and only if \(j \equiv i + 1 \pmod {m}\). For each \(i \in \mathbb {Z}_m\), consider

$$\begin{aligned} B_i := N_\mathrm {o}^{K}({i-1}) = N_\mathrm {o}^{G}({i-1}) \cap V(K) = \{v \in V(K) \mid (i-1, v) \in E(K)\}, \end{aligned}$$

i.e., \(B_i\) is the set of all outneighbours of \(i-1\) (addition modulo m) belonging to the strongly connected component K. Note that \(i \in B_i\) by definition. We show that for all \(i \in \mathbb {Z}_m\) and for all \(v \in B_i\), we have \(N_\mathrm {o}^{K}({v}) = B_{i+1}\). Let \(i \in \mathbb {Z}_m\) and \(v \in B_i\). Considering the closed walk \(i-1 \rightarrow i \rightarrow \dots \rightarrow m-1 \rightarrow 0 \rightarrow \dots \rightarrow i-1\) of length m and the edge \(i-1 \rightarrow v\), Lemma 4.5 gives the edge \(v \rightarrow i+1\) (note that by strong connectivity every vertex of K, in particular v, belongs to a cycle). Now let \(i \in \mathbb {Z}_m\), \(v \in B_i\) and \(w \in B_{i+1}\). Considering the closed walk \(i-1 \rightarrow i \rightarrow w \rightarrow i+2 \rightarrow \dots \rightarrow m-1 \rightarrow 0 \rightarrow \dots \rightarrow i-1\) of length m and the edge \(i-1 \rightarrow v\), Lemma 4.5 gives the edge \(v \rightarrow w\). We have shown thus far that for all \(i \in \mathbb {Z}_m\), \(B_{i+1} \subseteq N_\mathrm {o}^{K}({v})\) for all \(v \in B_i\).

Now let \(i \in \mathbb {Z}_m\), \(v \in B_i\), and let w be a vertex of K with \(v \rightarrow w\). We have shown above that \(v \rightarrow i+1\) is an edge. Considering the closed walk \(v \rightarrow i+1 \rightarrow \dots \rightarrow m-1 \rightarrow 0 \rightarrow 1 \rightarrow \dots \rightarrow i-1 \rightarrow v\) of length m and the edge \(v \rightarrow w\), Lemma 4.5 gives the edge \(w \rightarrow i+2\). Considering the closed walk \(i-1 \rightarrow v \rightarrow w \rightarrow i+2 \rightarrow \dots \rightarrow m-1 \rightarrow 0 \rightarrow 1 \rightarrow \dots \rightarrow i-1\) of length m and the edge \(i-1 \rightarrow i\), Lemma 4.5 gives the edge \(i \rightarrow w\). Thus \(w \in B_{i+1}\). This shows that for each vertex v of \(B_i\), \(N_\mathrm {o}^{K}({v}) \subseteq B_{i+1}\).

It remains to show that the sets \(B_0, B_1, \dots , B_{m-1}\) constitute a partition of V(K). Let us show first that these sets are pairwise disjoint. Suppose, to the contrary, that \(B_i \cap B_j \ne \emptyset \) for some \(i \ne j\), and let \(v \in B_i \cap B_j\). Then we have \(i-1 \rightarrow v \rightarrow i+1\) and \(j-1 \rightarrow v \rightarrow j+1\). We will find a contradiction by showing that K contains a cycle shorter than C. If \(j = i+1\), then K contains the loop \(v \rightarrow v\), a cycle of length 1. Otherwise \(v \rightarrow i+1 \rightarrow \dots \rightarrow j-1 \rightarrow v\) is a cycle shorter than C.

Suppose now, to the contrary, that \(\bigcup _{i=0}^{m-1} B_i \ne V(K)\), and let \(v \in V(K) \setminus \bigcup _{i=0}^{m-1} B_i\). Since K is strongly connected, there exists a path \(0 = v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_p = v\) in K. Then there exists an index \(q \in \{0, \dots , p-1\}\) such that \(v_q \in \bigcup _{i=0}^{m-1} B_i\) and \(v_{q+1} \notin \bigcup _{i=0}^{m-1} B_i\), say \(v_q \in B_j\). But we have shown above that \(N_\mathrm {o}^{K}({v_q}) = B_{j+1}\). This gives the desired contradiction, and we conclude that K is an m-whirl. \(\square \)

Lemma 4.9

Let \(t, t' \in B_n\), \(t \ne t'\), and let G be a digraph such that \(\mathbb {A}({G})\) satisfies the identity \(t \approx t'\). Then there is no path from a nontrivial strongly connected component of G to another.

Proof

Suppose, to the contrary, that there are distinct nontrivial strongly connected components K and \(K'\) and a path P from a vertex \(v \in V(K)\) to a vertex \(v' \in V(K')\). Assume that P is the shortest possible among all such paths. Then v is the only vertex of P lying in K. Let w be the successor of v along this path.

By Lemma 4.8, K and \(K'\) are an m-whirl and an \(m'\)-whirl, respectively, for some divisors m and \(m'\) of \(M_{t,t'}\). Hence v belongs to an m-cycle C in K and \(v'\) belongs to an \(m'\)-cycle \(C'\) in \(K'\). Now Lemma 4.5 provides an edge from w to a vertex on C. This means that w belongs to the strongly connected component K, a contradiction. \(\square \)

Definition 4.10

Let \(G = (V,E)\) be a digraph. A walk in G is pleasant, if all its vertices belong to trivial strongly connected components. Every pleasant walk is a path.

Lemma 4.11

Let \(t, t' \in B_n\), \(t \ne t'\), and let G be a digraph such that \(\mathbb {A}({G})\) satisfies the identity \(t \approx t'\). Then G has no pleasant path of length \(H_{t,t'}\).

Proof

Denote \(H := H_{t,t'}\), \(L := L_{t,t'}\). Suppose, to the contrary, that there exists a pleasant path \(v_0 \rightarrow v_1 \rightarrow \dots \rightarrow v_H\) in G. By Lemma 4.4, there is an index r with \(L+1 \le r \le H\) such that \((v_r, v_{L+1})\) is an edge of G. Consequently, \(v_{L+1}\) belongs to a nontrivial strongly connected component, a contradiction. \(\square \)

The necessary conditions established in the previous lemmas together are sufficient for the satisfaction of some nontrivial bracketing identity. We prove this in the following theorem, which provides a complete characterization of (not) antiassociative digraphs. Note that this does not constitute a necessary and sufficient condition for the satisfaction of a given nontrivial bracketing identity. Finding such a condition will be a topic of a forthcoming paper.

Theorem 4.12

Let G be a digraph. Then \(\mathbb {A}({G})\) is not antiassociative if and only if the following conditions hold.

  1. (i)

    Every nontrivial strongly connected component of G is a whirl.

  2. (ii)

    There is no path from a nontrivial strongly connected component of G to another.

  3. (iii)

    There is a finite upper bound on the length of the pleasant paths in G.

  4. (iv)

    There is a finite upper bound on the numbers m such that G contains an m-whirl.

Clearly, for finite graphs conditions (iii) and (iv) are fulfilled trivially.

Proof

Assume that \(\mathbb {A}({G})\) satisfies a nontrivial bracketing identity \(t \approx t'\). By Lemma 4.4, the pleasant paths in G have length less than \(H_{t,t'}\). By Lemma 4.8, every nontrivial strongly connected component of G is an m-whirl for some divisor m of \(M_{t,t'}\); such numbers m are clearly bounded above by \(M_{t,t'}\). By Lemma 4.9, there is no path from a nontrivial strongly connected component of G to another.

Assume now that conditions (i)–(iv) hold. We will construct a nontrivial bracketing identity \(t \approx t'\) that is satisfied by \(\mathbb {A}({G})\). We will define the terms t and \(t'\) in terms of the corresponding DFS trees \(T := G(t)\) and \(T' := G(t')\). Let P be an upper bound on the lengths of pleasant paths in G, as provided by condition (iii), and let

$$\begin{aligned} M := {{\,\mathrm{lcm}\,}}\{ m \in \mathbb {N}_{+} \mid G\text { contains an }m\text {-whirl} \}, \end{aligned}$$

which is a finite natural number by condition (iv), with the convention that \({{\,\mathrm{lcm}\,}}\emptyset = 1\). Let \(n := 3 P + M + 6\), and let T consist of the paths \(x_1 \rightarrow \dots \rightarrow x_{2 P + M + 4}\) and \(x_{2 P + M + 5} \rightarrow \dots \rightarrow x_{3 P + M + 6}\) and of the edge \(x_{P + 2} \rightarrow x_{2 P + M + 5}\). The tree \(T'\) is constructed in a similar way, but we replace the edge \(x_{P + 2} \rightarrow x_{2 P + M + 5}\) by \(x_{P + M + 2} \rightarrow x_{2 P + M + 5}\). If \(\varphi :X_n \rightarrow V(G)\) is a homomorphism of T into G, then there is an \(i \in [1, P + 2]\) such that \(\varphi (x_i)\) belongs to a nontrivial strongly connected component, by the definition of P. Similarly, \(\varphi (x_j)\) and \(\varphi (x_k)\) belong to a nontrivial strongly connected component for some \(j \in [P + M + 3, 2 P + M + 4]\) and for some \(k \in [2 P + M + 5, 3 P + M + 6]\). Condition (ii) implies that \(\varphi (x_i)\), \(\varphi (x_{i+1})\), ..., \(\varphi (x_j)\) are in the same nontrivial strongly connected component K, and this includes the vertices \(\varphi (x_{P+2})\), \(\varphi (x_{P+3})\), ..., \(\varphi (x_{P + M + 3})\). Similarly, also the vertices \(\varphi (x_{2 P + M + 5})\), ..., \(\varphi (x_k)\) belong to K. By the definition of M, the component K is an m-whirl for some divisor m of M. Therefore the vertices \(\varphi (x_{P+2})\) and \(\varphi (x_{P+M+2})\) belong to the same block B of K, and the vertices \(\varphi (x_{P+3})\), \(\varphi (x_{P+M+3})\) and \(\varphi (x_{2 P + M + 5})\) belong to the successor block \(B'\) of B. This implies that \(\varphi (x_{P + M + 2}) \rightarrow \varphi (x_{2 P + M + 5})\) is an edge, which proves that \(\varphi \) is also a homomorphism of \(T'\) into G. An analogous argument shows that if \(\varphi \) is a homomorphism of \(T'\) into G, then \(\varphi \) is also a homomorphism of T into G. Now if we let t and \(t'\) be the bracketings corresponding to T and \(T'\), respectively, then \(\mathbb {A}({G})\) satisfies \(t \approx t'\) by Proposition 2.1. \(\square \)

5 Some examples

In this section, we determine the associative spectrum of a few special directed graphs that are not covered by the results of the previous sections (i.e., they are neither associative nor antiassociative), such as directed paths and cycles, all graphs on two vertices, etc. For the spectra of directed paths, we shall need the number of DFS trees of bounded height, so first we recall some known facts about these numbers.

Let us denote the number of DFS trees of size n of height at most h by \(D_{h}(n)\). Clearly \(D_{h}(n) = C_{n-1}\) whenever \(n \le h + 1\), because every n-vertex rooted directed tree has height at most \(n-1\). The generating function \(\sum _{n=0}^{\infty } D_{h}(n) \cdot x^n\) is a rational function (see [8]), hence the sequence \(\{ D_{h}(n) \}_{n=0}^{\infty }\) satisfies a linear recurrence relation:

$$\begin{aligned} D_{h}(n+1)&=\left( {\begin{array}{c}h\\ 1\end{array}}\right) D_{h}(n)-\left( {\begin{array}{c}h-1\\ 2\end{array}}\right) D_{h}(n-1)+\left( {\begin{array}{c}h-2\\ 3\end{array}}\right) D_{h}(n-2)- \dots \\&=\sum _{k=0}^{\left\lfloor \frac{h-1}{2}\right\rfloor } (-1)^k \left( {\begin{array}{c}h-k\\ k+1\end{array}}\right) D_{h}(n-k). \end{aligned}$$

We list these recurrence relations for \(h=2,3,4,5\) in Table 1 together with explicit formulas for \(D_{h}(n)\) and the corresponding OEIS entries. (For \(h=5\) the characteristic polynomial of the linear recurrence is \(x^3-5x^2+6x-1\), and its roots are not “nice”, so we do not give an explicit formula for this case.) Note that we have every second Fibonacci number for \(h=3\). (We use the indexing \(F_1=F_2=1\).) For more information on the numbers \(D_{h}(n)\), see [8] (note that in [8] the height is defined as the number of vertices of the longest path starting at the root, whereas in this paper the number of edges is counted), and see also the OEIS entry A080934.

Table 1 Number of DFS trees with bounded height

Proposition 5.1

Let G be a directed path of length \(\ell \): \(v_0 \rightarrow v_1 \rightarrow \cdots \rightarrow v_\ell \). The associative spectrum of the corresponding graph algebra is

$$\begin{aligned} s_n(\mathbb {A}({G}))= {\left\{ \begin{array}{ll} D_{\ell }(n) = C_{n-1}, &{} \text {if }n \le \ell +1\text {,} \\ D_{\ell }(n)+1, &{} \text {if }n \ge \ell +2\text {.} \end{array}\right. } \end{aligned}$$

Proof

If T is a DFS tree with \(h(T)>\ell \), then there is no homomorphism from T to G; hence, all bracketings corresponding to DFS trees of height at least \(\ell +1\) belong to the same equivalence class of \(\sigma _n(\mathbb {A}({G}))\) by Proposition 2.1. (Note that such trees exist only if \(n \ge \ell +2\).) If \(h(T)\le \ell \), then there exist homomorphisms from T to G, for instance the collapsing map \(\varphi \) of T on G defined by \(\varphi (x_i)=v_{d_T(x_i)}\). Now if \(T'\) is another DFS tree of size n, then \(\varphi \) is a homomorphism of \(T'\) to G if and only if \(d_{T'}(x_i)=d_T(x_i)\) for all \(i\in [{n}]\), and this implies \(T'=T\) by Proposition 2.5. This together with Proposition 2.1 shows that each bracketing whose DFS tree has height at most \(\ell \) forms a singleton class in \(\sigma _n(\mathbb {A}({G}))\). There are \(D_{\ell }(n)\) such classes, and if \(n \ge \ell +2\), then we also have the class corresponding to trees of height at least \(\ell +1\).

\(\square \)

Next we examine directed paths with some loops. By Theorem 4.12 (or just by Lemma 4.9), if we have at least two loops on a path, then the graph is antiassociative, so it suffices to consider the case of only one loop. We determine the spectrum of directed paths with a loop on the last vertex; the other cases constitute a topic for further research. (However, see Proposition 5.7 for the path of length 1 with a loop on the first vertex.)

Lemma 5.2

Let \(\sim \) be the equivalence relation on \(B_n\) that relates t and \(t'\) if and only if \(T:=G(t)\) and \(T':=G(t')\) coincide up to level h, i.e., \(L_{t,t'}\ge h\). Then \(|{B_n/{\sim }}|=D_{h+1}(n)\).

Proof

The equivalence relation \(\sim \) on \(B_n\) induces naturally an equivalence relation on the set of zag sequences of length n, and we will use the same symbol \(\sim \) for this relation. For any zag sequence \({\mathbf {d}}=(d_1,\dots ,d_n)\), let \(\beta ({\mathbf {d}})=(d'_1,\dots ,d'_n)\) be the sequence obtained from \({\mathbf {d}}\) by replacing each element greater than h by \(h+1\), i.e., \(d'_i=\min (d_i,h+1)\) for \(i=1,\dots ,n\).Footnote 2 It is straightforward to verify that \(\beta ({\mathbf {d}})\) is also a zag sequence, and every zag sequence bounded above by \(h+1\) is in the image of \(\beta \) (indeed, if \({\mathbf {d}}\) is bounded by \(h+1\), then \(\beta ({\mathbf {d}})={\mathbf {d}}\)). Morover, for all zag sequences \(\mathbf {d_1},\mathbf {d_2}\) of size n, we have \(\beta (\mathbf {d_1})=\beta (\mathbf {d_2})\) if and only if \(\mathbf {d_1}\sim \mathbf {d_2}\). Thus \(\beta \) is a surjection from the set of all zag sequences of size n to the set of all zag sequences of size n bounded by \(h+1\), and the kernel of \(\beta \) is the equivalence relation \(\sim \). This implies that the number of equivalence classes of \(\sim \) equals the cardinality of the image of \(\beta \), which is clearly \(D_{h+1}(n)\). \(\square \)

Proposition 5.3

Let G be a directed path of length \(\ell \) with a loop on the last vertex: . The associative spectrum of the corresponding graph algebra is \(s_n(\mathbb {A}({G}))=D_{\ell }(n)\).

Proof

Homomorphisms of a DFS tree T into G are uniquely determined by the image of \(x_1\): a map \(\varphi :X_n \rightarrow V(G)\) with \(\varphi (x_1)=v_k\) is a homomorphism from T to G if and only if \(\varphi (x_i)=v_{d_T(x_i)+k}\) whenever \(d_T(x_i)<\ell -k\) and \(\varphi (x_i)=v_\ell \) whenever \(d_T(x_i)\ge \ell -k\). This implies, by Proposition 2.1, that \(\mathbb {A}({G})\) satisfies a bracketing identity \(t \approx t'\) if and only if \(L_{t,t'}\ge \ell -1\). Therefore, Lemma 5.2 gives \(s_n(\mathbb {A}({G}))=D_{\ell -1+1}(n)=D_{\ell }(n)\). \(\square \)

For the spectrum of the directed cycle \(\mathsf {C}_{m}\), we need to count depth sequences modulo m by Lemma 4.6 (or zag sequences modulo m, according to Proposition 2.6). The resulting numbers are called modular Catalan numbers in [10], and they are denoted by \(C_{m,n}\). For us it will be most convenient to define these numbers simply as \(C_{m,n} := s_{n+1}(\mathbb {A}({\mathsf {C}_{m}}))\), and we refer the reader to [10] for plenty of information on these numbers (tables of numerical values, references to OEIS entries, formulas and various combinatorial interpretations). We give two combinatorial interpretations in the next proposition. The second one is stated in [10], but the proof is left to the reader there, so we include the proof here.

Proposition 5.4

The associative spectrum \(s_n(\mathbb {A}({\mathsf {C}_{m}})) = C_{m,n-1}\) counts the number of zag sequences satisfying

$$\begin{aligned} d_{i+1}-d_i \in \{ 2-m,3-m,\dots ,0,1 \} \text { for all } i\in \{1,\dots ,n-1\}. \end{aligned}$$
(2)

Furthermore, \(s_n(\mathbb {A}({\mathsf {C}_{m}})) = C_{m,n-1}\) equals the number of Dyck paths of semilength \(n-1\) that do not contain \(D \cdots DU = D^m U\).

Proof

According to Proposition 2.6 and Lemma 4.6, the associative spectrum of \(\mathbb {A}({\mathsf {C}_{m}})\) counts the number of zag sequences modulo m. We claim that each zag sequence of length n is congruent modulo m to exactly one zag sequence \((d_1,\dots ,d_n)\) that satisfies (2).

Since \(\{ 2-m,3-m,\dots ,0,1 \}\) is a complete system of residues modulo m, it is clear that if two zag sequences satisfying (2) are congruent modulo m, then they are equal. (Note that since all zag sequences start with 0, the differences \(d_{i+1}-d_i\) uniquely determine the zag sequence.) To prove that every zag sequence is congruent to a zag sequence that satisfies (2), let \((d_1,\dots ,d_n)\) be an arbitrary zag sequence, and define the numbers \(0=d'_1,\dots ,d'_n\) recursively by \(d'_{i+1}=d'_i+(d_{i+1}-d_i)^*\), where \((d_{i+1}-d_i)^*\) is the unique element of the set \(\{ 2-m,3-m,\dots ,0,1 \}\) that is congruent to \(d_{i+1}-d_i\) modulo m. Obviously, we have \(d'_{i}\equiv d_i\pmod {m}\) and \(d'_{i+1}-d'_i \le 1\); we only need to prove that \(d'_i\ge 1\) for \(i=1,\dots ,n\). Since \(d_{i+1}-d_i \le 1\) by the definition of a zag sequence, we have \((d_{i+1}-d_i)^*\ge d_{i+1}-d_i\), and then, an easy induction argument proves that \(d'_i \ge d_i\) for \(i=1,\dots ,n\). This shows that \(d'_1,\dots ,d'_n\) is indeed a zag sequence; hence, our claim is proved.

We have proved so far that \(s_n(\mathbb {A}({\mathsf {C}_{m}}))\) equals the number of zag sequences that satisfy (2). Note the difference between (1) and (2): an arbitrary zag sequence can have arbitrarily large decreases, while a sequence satisfying (2) can drop at most by \(m-2\).Footnote 3 To prove the statement about Dyck paths, let us rewrite (2) in terms of the corresponding DFS tree T:

$$\begin{aligned} d_T(x_{i+1}) \ge d_T(x_i) - (m-2) \text { for all } i\in \{1,\dots ,n-1\}. \end{aligned}$$
(3)

If \(x_{i+1}\) is a child of \(x_i\), then this inequality holds trivially (in this case we have \(d_T(x_{i+1})=d_T(x_i)+1\)). Otherwise, \(x_{i+1}\) is a child of one of the ancestors \(x_p\) of \(x_i\); thus, the depth-first search goes down to \(x_p\) (which has been visited before) after the first visit of \(x_i\), and then, from \(x_p\) it takes one step up to reach \(x_{i+1}\) for the first time. This can be seen in the Dyck path (see Remark 2.7) as a sequence of steps \(D \cdots DU=D^kU\) from the point labelled by \(x_i\) to the point labelled by \(x_{i+1}\). (For example, in Fig. 3 we have the steps DDU from the label \(x_4\) to the label \(x_5\).) The number of down-steps here is \(k=d_T(x_i)-d_T(x_p)=d_T(x_i)-d_T(x_{i+1})+1\). Thus (3) is equivalent to \(k \le m-1\); hence, (2) means that any sequence of consecutive steps of the form \(D \cdots DU\) in the Dyck path can have at most \(m-1\) down-steps. \(\square \)

Remark 5.5

Proposition 5.4 implies that \(s_n(\mathbb {A}({\mathsf {C}_{m}}))\) is nondecreasing in m, hence \(s_n(\mathbb {A}({\mathsf {C}_{m}})) \ge s_n(\mathbb {A}({\mathsf {C}_{2}})) = 2^{n-2}\) for all \(m \ge 2\) (see Lemma 3.1). The results of [7] and [10] imply that the associative spectrum of \(\mathbb {A}({\mathsf {C}_{m}})\) coincides with that of the operation \(x + \varepsilon y\) on complex numbers, where \(\varepsilon \) is a primitive m-th root of unity. In particular, for \(m = 2\), we have that the spectrum of subtraction consists of powers of 2 (see 3.1 in [7]).

Now let us study digraphs on two vertices systematically. Up to isomorphism, there are ten digraphs on two vertices; they are presented in Table 2. The corresponding graph algebras are three-element groupoids, and the last column of the table indicates the Siena Catalog numbers of their isomorphism class representatives as listed in [1], as well as the ones of their opposite groupoids. Of these ten digraphs, only three are not covered by Proposition 4.1 and Theorem 4.12 (i.e., they are neither associative nor antiassociative): the undirected path of length one, the directed path of length one, and the directed path of length one with a loop on the first vertex. The first two ones are special cases of Theorem 3.3 and Proposition 5.1, respectively. We treat the third one in Proposition 5.7, and for that we need to investigate an equivalence relation on DFS trees determined by their leaves.

Table 2 Digraphs on two vertices and their associative spectra

Let T and \(T'\) be DFS trees on n vertices. We say that T and \(T'\) are leaf-equivalent if they have the same set of leaves.

Lemma 5.6

For \(n > 1\), the number of leaf-equivalence classes of DFS trees on n vertices is \(2^{n-2}\).

Proof

The set of leaves of a DFS tree on n vertices is a subset of \(X_n\) that does not contain the root \(x_1\), but it always contains \(x_n\). On the other hand, it is easy to see that for every subset \(S = \{x_{i_1}, x_{i_2}, \dots , x_{i_r}\} \subseteq X_n\) with \(1< i_1< i_2< \dots < i_r = n\), there exists a DFS tree whose leaves are precisely the elements of S. For example, we can take the tree comprising just the paths from \(x_1\) to each \(x_{i_j} \in S\) that are disjoint except for the initial vertex: \(x_1 \rightarrow x_2 \rightarrow \dots \rightarrow x_{i_1}\) and \(x_1 \rightarrow x_{i_{j-1} + 1} \rightarrow \dots \rightarrow x_{i_j}\) for \(2 \le j \le r\). The number of subsets of \(X_n\) containing \(x_n\) but not containing \(x_1\) is \(2^{n-2}\).

\(\square \)

Proposition 5.7

The associative spectrum \(s_n\) of the graph algebra corresponding to the graph G given by \(V(G)=\{v,w\},~E(G)=\{(v,v),(v,w)\}\) is \(s_n=2^{n-2}\).

Proof

For any DFS tree T of size n, a map \(\varphi :X_n\rightarrow \{v,w\}\) is a homomorphism of T into G if and only if all vertices that are mapped to w are leaves in T. Therefore, \(\mathbb {A}({G})\) satisfies a bracketing identity \(t\approx t'\) if and only if the corresponding trees \(T:=G(t)\) and \(T':=G(t')\) are leaf-equivalent. Now Lemma 5.6 implies that \(s_n=2^{n-2}\). \(\square \)

Finally, we consider some graphs on three vertices.

Proposition 5.8

The associative spectrum of the graph algebra corresponding to the graph G given by \(V(G) = \{u,v,w\}\), \(E(G) = \{(u,v),(v,v),(u,w),(w,w)\}\) is \(s_n(\mathbb {A}({G})) = 2^{n-2}\).

Proof

For any DFS tree T of size n, a map \(\varphi :X_n \rightarrow \{u,v,w\}\) is a homomorphism of T into G if and only if either \(\varphi (X_n) = v\) or \(\varphi (X_n) = w\), or \(\varphi (x_1) = u\) and all other vertices are mapped to \(\{v,w\}\) in such a way, that if a vertex of depth one is mapped to v (to w), then all of its descendants are also mapped to v (to w):

$$\begin{aligned} \forall p \in X_n:d_{T}(p)=1 \implies \varphi (V(T_p))=\{\varphi (p)\} \in \{\{v\},\{w\}\}. \end{aligned}$$

Thus the set of all homomorphisms of T into G is determined by the partition \(\{V(T_p) \mid p \in X_n \text { and } d_{T}(p) = 1\}\) of the set \(\{x_2,\dots ,x_n\}\). This partition is in turn determined uniquely by the set of depth-one vertices. Indeed, if the depth-one vertices of T are \(x_{i_1},\dots ,x_{i_{s}}\) with \(2 = i_1< \dots <i_{s} \le n\), then \(V(T_{x_{i_k}}) = X_{[i_k,i_{k+1}-1]}\) for \(k = 1,\dots ,s-1\) and \(V(T_{x_{i_{s}}}) = X_{[i_{s},n]}\). By Proposition 2.1, this implies that \(\mathbb {A}({G})\) satisfies a bracketing identity \(t \approx t'\) if and only if \(L_{t,t'}\ge 1\). Therefore, by Lemma 5.2 we have \(s_n(\mathbb {A}({G})) = D_{2}(n) = 2^{n-2}\). \(\square \)

Proposition 5.9

The associative spectrum of the graph algebra corresponding to the graph G given by \(V(G) = \{u,v,w\}\), \(E(G) = \{(u,v),(v,v),(v,w),(w,v),(w,w)\}\) is \(s_n(\mathbb {A}({G})) = 2^{n-2}\).

Proof

For any DFS tree T of size n, a map \(\varphi :X_n \rightarrow \{u,v,w\}\) is a homomorphism of T into G if and only if either \(\varphi (X_n) \subseteq \{v,w\}\), or \(\varphi (x_1) = u\), all depth-one vertices are mapped to v, and the other vertices are mapped to \(\{v,w\}\) in an arbitrary way. Thus the set of all homomorphisms of T into G is determined uniquely by the set of depth-one vertices. Therefore, just as in the previous proposition, we can conclude \(s_n(\mathbb {A}({G})) = D_{2}(n) = 2^{n-2}\) with the help of Lemma 5.2. \(\square \)

Remark 5.10

The graph algebra of the directed path of length one with loops on both vertices is isomorphic to the three-element groupoid with Siena Catalog number 84 and antiisomorphic to the one with number 82 (see [1]). These groupoids were shown in [7, statements 2.4, 5.7] to be antiassociative; this result also follows immediately from our Lemma 4.9.