## Abstract

The syntactic structure of a sentence is often represented using syntactic dependency trees. The sum of the distances between syntactically related words has been in the limelight for the past decades. Research on dependency distances led to the formulation of the principle of dependency distance minimization whereby words in sentences are ordered so as to minimize that sum. Numerous random baselines have been defined to carry out related quantitative studies on lan- guages. The simplest random baseline is the expected value of the sum in unconstrained random permutations of the words in the sentence, namely, when all the shufflings of the words of a sentence are allowed and equally likely. Here we focus on a popular baseline: random projective per- mutations of the words of the sentence, that is, permutations where the syntactic dependency structure is projective, a formal constraint that sentences satisfy often in languages. Thus far, the expectation of the sum of dependency distances in random projective shufflings of a sentence has been estimated approximately with a Monte Carlo procedure whose cost is of the order of Rn, where n is the number of words of the sentence and R is the number of samples; it is well known that the larger R is, the lower the error of the estimation but the larger the time cost. Here we pre- sent formulae to compute that expectation without error in time of the order of n. Furthermore, we show that star trees maximize it, and provide an algorithm to retrieve the trees that minimize it.

## 1 Introduction

A successful way to represent the syntactic structure of a sentence is a dependency graph (Nivre 2006) that relates the words of a sentence by pairing them with syntactic links, as in Figure 1. Each link is directed and the arrow points from the **head word** to the **dependent word** (Figure 1). There are several conditions that are often imposed on the structure of dependency graphs (Nivre 2006). The first is **well-formedness**, namely, the graph is (weakly) connected. The second is **single-headedness**, that is, every word has at most one head. Another condition is **acyclicity**, that is, if two words, say *w*_{i} and *w*_{j}, are connected via following one or more directed links from *w*_{i} to *w*_{j} then there is no path of directed links from *w*_{j} to *w*_{i}. By definition, syntactic dependency trees always have a root vertex, that is, a vertex (word) with no head. The fourth condition is **projectivity**, often informally described as the situation where edges do not cross when drawn above the sentence and the root is not covered by any edge.

When a dependency graph is well-formed, single-headed, and acyclic, the graph is a directed tree, called a syntactic dependency tree (Kuhlmann and Nivre 2006; Gómez-Rodríguez, Carroll, and Weir 2011). In addition, a syntactic dependency structure is projective if, for every vertex *v*, all vertices reachable from *v*, that is, the yield of *v*, form a continuous substring within the linear ordering of the sentence (Kuhlmann and Nivre 2006). Equivalently, a syntactic dependency structure is projective if the yield of each vertex of the tree forms a contiguous interval of positions in the linear ordering of the vertices. Kuhlmann and Nivre (2006) define an interval (with endpoints *i* and *j*) as the set [*i*,*j*] = {*k* | *i* ≤ *k*and *k* ≤ *j*}.

A linear arrangement of a graph is planar if it does not have edge crossings (Sleator and Temperley 1993; Kuhlmann and Nivre 2006). Then projectivity can be characterized as a combination of two properties: planarity and the fact that the root is not covered (Mel’čuk 1988). Planarity was, to the best of our knowledge, first thought of as **one-page embeddings** of trees by Bernhart and Kainen (1979). Figure 1 shows an example of a projective tree 1(a), a planar tree 1(b), and a non-planar tree 1(c) (see Bodirsky, Kuhlmann, and Möhl [2005] for further characterizations of syntactic dependency structures).

A free tree *T* = (*V*,*E*) is an undirected acyclic graph (Figure 2(a)), where *V* is the set of vertices and *E* is the set of edges. Here we represent the syntactic dependency structure of a sentence as a pair consisting of a rooted tree and a linear arrangement of its vertices. A rooted tree *T*^{r} = (*V*,*E*;*r*) is a free tree *T* = (*V*,*E*) with one of its vertices, say *r* ∈ *V*, labeled as its root and with the edges oriented from *r* toward the leaves (Figure 2(b)). A linear arrangement π (also called **embedding**) of an *n*-vertex graph *G* = (*V*,*E*) is a (bijective) function that assigns every vertex *u* ∈ *V* to a position π(*u*). Throughout this article, we use the terms “linear arrangement,” “linear ordering,” “arrangement,” and “linearization” interchangeably. In addition, we assume that π(*u*) ∈ [*n*] = {1,⋯ ,*n*}. Linear arrangements are often seen as determined by the labeling of the vertices (Chung 1984; Kuhlmann and Nivre 2006), but here we consider that the labeling of a graph and π are independent. In order to clarify our notion of linear arrangement of a labeled graph *G*, we say that two linear arrangements π_{1} and π_{2} of *G* are equal if and only if, for every vertex *u* ∈ *V*, it holds that π_{1}(*u*) = π_{2}(*u*).

*G*= (

*V*,

*E*), one can define properties on the graph’s edges and on the arrangement as a whole. The length of an edge between vertices

*u*and

*v*is their distance in the linear arrangement, usually defined as

*G*when it is linearly arranged by π, but we also derive some results for $D\pi *(G)=\u2211uv\u2208E\delta uv*(\pi )$.

*O*(

*n*)-time algorithm for planar (one-page) embedding of free trees. Gildea and Temperley (2007) sketched an algorithm for projective embeddings of rooted trees. Alemany-Puig, Esteban, and Ferrer-i-Cancho (2022) reviewed this problem and presented, to the best of our knowledge, the first

*O*(

*n*)-time algorithm. Polynomial-time algorithms for unconstrained embeddings were presented by Shiloach (1979), with complexity

*O*(

*n*

^{2.2}), and later by Chung (1984), with complexities

*O*(

*n*

^{2}) and

*O*(

*n*

^{λ}), where

*λ*is any real number satisfying $\lambda >log3/log2$. Concerning random baselines, the precursors are found in Zörnig’s research on the distribution of the distance between repeats in a uniformly random arrangement of a sequence assuming that consecutive elements are at distance zero (Zörnig 1984) as in parallel research on syntactic dependency distances (Hudson 1995; Hiranuma 1999; Eppler 2005; Liu, Xu, and Liang 2017). Later, Ferrer-i-Cancho (2004, 2016) studied the expectation of the random variable

*D*(

*T*) defined as

_{uv}is a random variable defined over uniformly random unconstrained linear arrangements of the tree

*T*, resulting in

*T*.

While there are constant-time formulae for the expectation of *D*(*T*) in unconstrained arrangements (Equation (4)), a procedure to calculate the expected value of *D*(*T*) under projectivity is not forthcoming. Our primary goal is to improve the calculation of the expected sum of edge lengths in uniformly random projective arrangements with respect to the Monte Carlo method or random sampling method put forward by Gildea and Temperley (2007). Such a widely used procedure (Park and Levy 2009; Futrell, Mahowald, and Gibson 2015; Kramer 2021) estimates the expectation of *D* of an *n*-vertex tree with an error that is negatively correlated with *R*, the amount of arrangements sampled, while its cost is directly proportional to that amount, that is, *O*(*Rn*). This raises the question of what the minimum value of *R* would be to obtain accurate-enough estimations of the expectation of *D*(*T*) in projective arrangements. In recent research (Futrell, Mahowald, and Gibson 2015; Kramer 2021), *R* = 10,*R* = 100 were used. Here we demonstrate that there is no need to answer this question since we provide formulae to calculate its exact value.

We improve upon these techniques by providing closed-form formulae for the expected value of *D*(*T*^{r}) in uniformly random projective arrangements of *T*^{r} that can be evaluated in *O*(*n*)-time. More formally, our goal in this article is to find closed-form formulae for $Epr[D(Tr)]$, the expectation of the random variable *D*(*T*^{r}) conditioned to the set of projective arrangements, where the subscript “pr” indicates “projective linear arrangement.” Notice that $E[D(T)]$ in Equation (4) has no subscript to indicate **unconstrained linear arrangement**. An unconstrained linear arrangement is one of the *n*! possible orderings. $Epr[D(Tr)]$ is a widely used random baseline for research on DDm (Park and Levy 2009; Gildea and Temperley 2010; Futrell, Mahowald, and Gibson 2015; Kramer 2021).

The structure of this article is as follows. We first derive, in Section 2, an arithmetic expression for $Epr[D(Tr)]$, given by

*T*

^{r}= (

*V*,

*E*;

*r*) be a tree rooted at

*r*∈

*V*. The expected sum of edge lengths

*D*(

*T*

^{r}) conditioned to uniformly random projective arrangements is

*n*

_{u}denotes the number of vertices of the subtree $Tur$ rooted at

*u*∈

*V*, that is, $nu=|V(Tur)|$,

*Γ*

_{v}denotes the set of children of vertex

*v*, and

*d*

_{v}= |

*Γ*

_{v}| is the out-degree of vertex

*v*in the rooted tree. If

*d*

_{r}= 0 then $Epr[D(Tr)]=0$.

For any *n*-vertex rooted tree *T*^{r}, we have that $Epr[D(Tr)]\u2264Epr[D(Snh)]$ with equality if, and only if, $Tr=Snh$, where $Snh$ denotes the star tree of *n* vertices.

Then, a tight upper bound of $Epr[D(Tr)]$ is given by $E[D(T)]$, as detailed in the next corollary.

*n*-vertex rooted tree

*T*

^{r}= (

*V*,

*E*;

*r*) rooted at

*r*∈

*V*, it holds that

*T*is the free tree variant of

*T*

^{r}.

Theorem 1 and Corollary 1 indicate that, for each *n*, a star tree rooted at its hub ($Snh$) maximizes $Epr[D(Tr)]$, achieving (*n*^{2} − 1)/3. Section 3 also shows that the minima can be calculated with a dynamic programming algorithm.

Section 4 compares our new method to calculate $Epr[D(Tr)]$ exactly against the Monte Carlo estimation method using dependency treebanks and finds that commonly used values of *R* can yield a large relative error in the estimation on a single tree. This new method is available in the Linear Arrangement Library (Alemany-Puig, Esteban, and Ferrer-i-Cancho 2021). We finally present some conclusions and propose future work in Section 5.

## 2 Expected Sum of Edge Lengths

We devote this section to characterize projective arrangements (Section 2.1) and to derive an arithmetic expression to calculate the sum of expected edge lengths in said arrangements (Section 2.3). We end this section with some instantiations of said expression for particular classes of trees (Section 2.4).

### 2.1 The Number of Random Projective Arrangements

The number of unconstrained arrangements of an *n*-vertex tree *T* is **N**(*T*) = |**P**(*T*)| = *n*!, where **P**(*T*) denotes the set of all *n*! arrangements of *T*, hence **N**(*T*) is independent from the tree structure. The number of projective arrangements of a tree, however, depends on its structure, in particular on the out-degree sequence of the tree, as is shown later in this section. Counting the number of projective arrangements of a tree motivates a proper characterization that underpins the proof of Theorem 1. For this, we need to introduce some notation.

Henceforth we denote directed edges of a rooted tree *T*^{r} = (*V*,*E*;*r*) as *uv* =(*u*,*v*) ∈ *E*; all edges are oriented toward the leaves. We denote the set of children of a vertex *v* ∈ *V* as *Γ*_{v}, and thus the out-degree of *v* is *d*_{v} = |*Γ*_{v}| in the rooted tree. In particular, we refer to the root’s children as $\Gamma r={u1,\cdots ,udr}\u2282V$. We denote the subtree of *T*^{r} rooted at *u* ∈ *V* as $Tur$; we denote its size (in vertices) as $nu=|V(Tur)|$; notice that *n*_{u} ≥ 1. We say that $Tvr$ is an immediate subtree of $Tur$ if *uv* is an edge of the tree. Figure 3 depicts a rooted tree and the immediate subtrees of *T*^{r}.

We provide a closed-form formula for the number of projective arrangements of a rooted tree, **N**_{pr}(*T*^{r}). This result helps us characterize said arrangements.

*T*

^{r}= (

*V*,

*E*;

*r*) be a tree rooted at

*r*∈

*V*.

*d*

_{v}is the out-degree of vertex

*v*in the rooted tree. If

*d*

_{r}= 0, then

**N**

_{pr}(

*T*

^{r}) = 1.

The fact that subtrees span over intervals (Kuhlmann and Nivre 2006) is central to the proof of Proposition 1. Because intervals are associated with a fixed pair of starting and ending positions in a linear sequence, we use the term **segment** of a rooted tree $Tur$ to refer to a real segment within the linear ordering containing all vertices of $Tur$ (Figure 4); technically, that segment is an interval of length *n*_{u} whose starting and ending positions are unknown until the whole tree is fully linearized. Thus, a segment is a movable set of vertices within the linear ordering. The concept of *segment* is equivalent to the notion of continuous *constituent* in headed phrase structure representations (Kuhlmann and Nivre 2006). Hereafter, for simplicity, we refer to the “segment of a tree in a linear arrangement” simply as “segment of a tree,” assuming that such a segment is defined with respect to a linear arrangement.

*Proof of Proposition 1.*

We can associate a set of segments to each vertex. The set of vertex *u* contains *d*_{u} + 1 segments: one segment corresponds to *u* (the only segment of length 1), and the remaining *d*_{u} segments correspond to the immediate subtrees of $Tur$. We obtain a projective linear arrangement by permuting the elements of each set for all vertices. Therefore, a projective arrangement can be seen as being recursively composed of permutations of sets of segments. Such “recursion” starts at the permutation of the set of segments associated with *r*. Note, then, that there are (*d*_{u} + 1)! possible permutations of the segments associated to vertex *u*. For a fixed permutation of the segments associated with *r*, there are $\u220fu\u2208\Gamma rNpr(Tur)$ different projective arrangements of its immediate subtrees $Tur$, hence the recurrence in Equation (8). Equation (9) follows upon unfolding the recurrence.

The proof of Proposition 1 can be used to devise a simple procedure to generate projective arrangements uniformly at random, and another to enumerate all projective arrangements, of a rooted tree. As explained in previous articles (Gildea and Temperley 2007; Futrell, Mahowald, and Gibson 2015), the former method consists of first generating a uniformly random permutation of the *d*_{v} + 1 segments associated with every vertex *v* ∈ *V* and, afterward, constructing the arrangement using these permutations. When a tree is linearized using the permutations of the sets of segments, we say that each segment becomes an interval.

### 2.2 The Expected Sum of Edge Lengths in Random Arrangements

We first review the problem of computing $E[D(T)]$—the expected value of *D*(*T*) in uniformly random unconstrained arrangements—so as to introduce the methodology applied for $Epr[D(Tr)]$. The calculation requires two steps: first, the calculation of $E[\delta uv]$, the expected length of an arbitrary edge joining vertices *u* and *v*, and second, the calculation of $E[D(T)]$; henceforth we denote these values as $E[D]$ and $E[\delta ]$ since they only depend on the size of *T*, not on its topology. For simplicity, we assume the definition of edge length in Equation (1).

**N**(

*T*) =

*n*! unconstrained linear arrangements and 2(

*n*− δ)(

*n*− 2)! unconstrained arrangements where the pair of vertices are at distance δ, hence

*D*in an unconstrained arrangement. Since a tree has

*n*− 1 edges and applying linearity of expectation, $E[D]=(n\u22121)E[\delta ]$, which gives Equation (4). Note that neither $E[\delta uv]$ nor $E[D(T)]$ depend on

*T*’s topology (excluding

*n*, the size of the tree).

### 2.3 The Expected Sum of Edge Lengths in Random Projective Arrangements

To obtain an arithmetic expression for $Epr[D(Tr)]$, we follow again a two-step approach. First, we calculate the expected length of an edge in uniformly random projective arrangements. However, unlike the unconstrained case, the edge must be incident to the root. Second, we calculate the expected $Epr[D(Tr)]$ applying the result of the first step. Before we proceed, we need to introduce some notation.

An edge connecting the root of the tree (*r*) with one of its children (*u*) can be decomposed into two parts: its **anchor** (Shiloach 1979; Chung 1984) and its **coanchor** (Figure 4). Such decomposition is also found in Gildea and Temperley (2007) and Park and Levy (2009), but using different terminology. In the context of projective linear arrangements, we define α_{ru}(π) as the length of the anchor, that is, the number of positions of the linear arrangement covered by the edge *ru* in the segment of $Tur$ including the end of the edge π(*u*); similarly, we define *β*_{ru}(π) as the number of positions of the linear arrangement that are covered by that edge in segments other than that of $Tur$ and *r*. Put differently, α_{ru}(π) is the width of the part of $Tur$ covered by the edge *ru* including the end of the edge π(*u*); similarly, *β*_{ru} is the total width of $Tvr$ over all *r*’s children *v* that fall between *r* and *u*. Then the length of an edge connecting *r* with *u* is δ_{ru}(π) = |π(*r*) − π(*u*)| = α_{ru}(π) + *β*_{ru}(π).

The next lemma shows that the expected value of δ_{ru} depends only on the size of the whole tree (*n*_{r}) and the size of the subtree rooted at the child (*n*_{u}).

*T*

^{r}= (

*V*,

*E*;

*r*) be a tree rooted at

*r*∈

*V*. Given an edge

*ru*∈

*E*, its anchor’s expected length in uniformly random projective arrangements is

*ru*∈

*E*in such arrangements is

*Proof.*

_{pr}(π(

*u*) < π(

*r*)) is the probability that

*u*precedes

*r*in a random projective linear arrangement and ℙ

_{pr}(π(

*u*) > π(

*r*)) +ℙ

_{pr}(π(

*u*) < π(

*r*)) = 1. As any projective linear arrangement such that

*u*precedes

*r*has a reverse projective arrangement where

*u*follows

*r*, then ℙ

_{pr}(π(

*u*) < π(

*r*)) = 1/2 and

*q*

_{u}be the relative position of vertex

*u*in its segment in the (projective) linear arrangement (the

*i*th vertex of said segment is at relative position

*i*). If

*u*precedes

*r*in the linear arrangement (π(

*u*) < π(

*r*)) as in Figure 4, then α

_{ru}=

*n*

_{u}−

*q*

_{u}+ 1. If

*u*follows

*r*in the linear arrangement (π(

*r*) < π(

*u*)), α

_{ru}=

*q*

_{u}. Applying these two results, we obtain

*β*

_{ru}, we define

*s*

_{ru}as the number of intermediate segments between

*r*and the segment of $Tur$ in the linear arrangement. Therefore,

*β*

_{ru}can be decomposed in terms of the lengths of each of these segments. The length of the

*i*th segment in, say, the left-to-right order, is denoted as $\phi ru(i)$. Formally,

*β*

_{ru}can be decomposed as

*β*

_{ru}given that

*u*and

*r*are separated by

*s*segments, and ℙ

_{pr}(

*s*

_{ru}=

*s*) is the probability that

*u*and

*r*are separated by

*s*segments, both in uniformly random projective arrangements. On the one hand,

*r*and $Tur$. On the other hand, ℙ

_{pr}(

*s*

_{ru}=

*s*) is the proportion of projective linear arrangements where the segments of $Tur$ and that of

*r*are separated by

*s*segments in the linear arrangement, that is

Now we can derive an arithmetic expression for $Epr[D(Tr)]$.

*Proof of Theorem 1 (stated on page 494).*

*D*(

*T*

^{r}) over the probability space of uniformly random (unconstrained) linear arrangements of

*T*

^{r}, as defined above. This variable can be decomposed into two summations

*T*

^{r}. The second summation groups the edges incident to the root

*r*. Then, we can use linearity of expectation to obtain

In the proof above we implicitly use our definition of edge length δ_{uv}(π) (Equation (1)). Nevertheless, the expression in Equation (6) can be easily adjusted to use different definitions of edge length, for example, $\delta uv*(\pi )$ (Equation (2)). It suffices to find an appropriate transformation of our definition of *D*(*T*^{r}) (Equation (3)) into the one desired, namely, *D*^{*}(*T*^{r}). The next corollary gives the solution.

*T*

^{r}= (

*V*,

*E*;

*r*) be a tree rooted at

*r*∈

*V*. We have that

*Proof of Corollary 2.*

It is easy to see that Equations (6) and (31) can both be evaluated in *O*(*n*)-time and *O*(*n*)-space, where *n* is the number of vertices of the tree: One only needs to compute the values *n*_{v} in *O*(*n*)-time, store them in *O*(*n*) space, and then evaluate the formula, also in *O*(*n*)-time using those values. In the analysis above, we are assuming that the values of *d*_{v} are already computed; depending on the data structure used to represent the tree, the cost of computing *d*_{v} might be relevant.

### 2.4 Formulae for Classes of Trees

Here we consider three kinds of free trees that are later transformed into rooted trees (Harary 1969; Valiente 2021). First, **linear** (or **path**) trees are trees in which the maximum degree is 2. **Star** trees consist of a vertex connected to *n* − 1 leaves; also, a complete bipartite graph *K*_{1,n−1}. A **quasi-star** tree is a star tree in which one of its edges has been subdivided once with a vertex in the middle.^{1} For the following analyses, we define the hub of a rooted tree as the vertex of the underlying free tree that has the highest degree; we also use the term “leaf” to refer to a leaf in the underlying free tree. We now instantiate Equations (6) and (9) for several classes of trees (Table 1): Star trees, $Sn$, rooted at the hub, $Snh$, and at a leaf, $Snl$; Quasi-star trees, $Qn$, rooted at the hub, $Qnh$, at a leaf adjacent to the hub, $Qnhl$, at the leaf not adjacent to the hub $Qne$, and at the only internal vertex that is not the hub, $Qnb$; Linear trees when rooted at a vertex at distance *k* ≥ 0 from one of the leaves, $Lnk$. Each class of tree is depicted in Figure 5. These classes of trees are chosen for graph theoretic reasons. Linear trees minimize the variance of the degree (Ferrer-i-Cancho 2013); star graphs maximize it (Ferrer-i-Cancho 2013) and all their unconstrained linear arrangements are planar; concerning $Snh$, all its linear arrangements are projective; quasi-star trees maximize the variance of the degree among trees whose set of unconstrained arrangements contains some non-planar arrangement (Ferrer-i-Cancho 2016).

**Table 1**

Class of tree . | T^{r}
. | N_{pr}(T^{r})
. | $Epr[D(Tr)]$ . |
---|---|---|---|

Star | $Snh$ | n! | (n^{2} − 1)/3 |

$Snl$ | 2(n − 1)! | n(2n − 1)/6 | |

Quasi-star (n ≥ 4) | $Qnh$ | 2(n − 1)! | (2n^{2} − 2n + 3)/6 |

$Qne$ | 4(n − 2)! | (2n^{2} − 2n + 3)/6 | |

$Qnb$ | 6(n − 2)! | (2n^{2} − 3n + 7)/6 | |

$Qnhl$ | 4(n − 2)! | (2n^{2} − 3n + 7)/6 | |

Linear | $Ln0$ | 2^{n−1} | (n − 1)(n + 2)/4 |

$Lnk$, (k > 0) | 3 · 2^{n−2} | [(n − 1)(3n + 10) + 6k(k + 1 − n)]/12 |

Class of tree . | T^{r}
. | N_{pr}(T^{r})
. | $Epr[D(Tr)]$ . |
---|---|---|---|

Star | $Snh$ | n! | (n^{2} − 1)/3 |

$Snl$ | 2(n − 1)! | n(2n − 1)/6 | |

Quasi-star (n ≥ 4) | $Qnh$ | 2(n − 1)! | (2n^{2} − 2n + 3)/6 |

$Qne$ | 4(n − 2)! | (2n^{2} − 2n + 3)/6 | |

$Qnb$ | 6(n − 2)! | (2n^{2} − 3n + 7)/6 | |

$Qnhl$ | 4(n − 2)! | (2n^{2} − 3n + 7)/6 | |

Linear | $Ln0$ | 2^{n−1} | (n − 1)(n + 2)/4 |

$Lnk$, (k > 0) | 3 · 2^{n−2} | [(n − 1)(3n + 10) + 6k(k + 1 − n)]/12 |

*k*> 0, we have

## 3 Maxima and Minima

In this section, we tackle the problem of computing the minima and characterizing the maxima of $Epr[D(Tr)]$, both over all *n*-vertex root trees (keeping *n* constant). In particular, we give a closed-form formula for the maximum value of $Epr[D(Tr)]$ and characterize the trees that maximize it, as well as outline a dynamic programming algorithm to compute the minima. Henceforth, we use $Tn$ to denote the set of *n*-vertex (unlabeled) rooted trees. Evidently, any tree that maximizes (respectively, minimizes) $Epr[D(Tr)]$ also maximizes (respectively, minimizes) $Epr[D*(Tr)]$; thus we restrict our study to the former. Throughout this section, we use *n*_{i} to refer to the size of the subtree rooted at the *i*th child of the root for 1 ≤ *i* ≤ *d*_{r}.

The construction of projective minimum linear arrangements has optimal substructure: Optimal arrangements are composed of optimal arrangements of subtrees (Hochberg and Stallmann 2003; Gildea and Temperley 2007; Alemany-Puig, Esteban, and Ferrer-i-Cancho 2022). Similarly, the construction of *n*-vertex rooted trees $Tr\u2208Tn$ that maximize (respectively, minimize) $Epr[D(Tr)]$ also has optimal substructure. The following lemma proves this claim.

*n*vertices.

*f*(

*n*), the optimal value of $Epr[D(Tr)]$ satisfies

*Proof.*

We can construct an *n*-vertex optimal tree using optimal subtrees. We can obtain the right-hand side of Equation (40) using the recurrence in Equation (5). An optimal *n*-vertex tree is one whose cost value is optimal among all optimal *n*-vertex trees whose root has fixed degree *d*_{r} ∈{1,⋯ ,*n* − 1}. Given a fixed root degree *d*_{r} such that 1 ≤ *d*_{r} ≤ *n* − 1, an optimal *n*-vertex rooted tree can be built by constructing an optimal (*n* − 1)-vertex forest of *d*_{r} rooted trees, each of size *n*_{i} vertices and optimal among the *n*_{i}-vertex trees. Choosing the *d*_{r} trees to be *n*_{i}-optimal makes the sum of their costs, $\u2211if(ni)$, optimal.

In subsequent paragraphs we use *f*_{M}(*n*) to denote the *maximization* variant and *f*_{m}(*n*) to denote the *minimization* variant of *f*(*n*), respectively. Theorem 2 characterizes the maxima of $Epr[D(Tr)]$. Perhaps not so surprisingly, the only maximum of $Epr[D(Tr)]$ is obtained by $Snh$.

*Proof of Theorem 2 (stated on page 495).*

We prove this by induction on *n* using the formalization of the optimum in Equation (40). The base cases can be easily obtained by an exhaustive enumeration of the (unlabeled) rooted trees of *n* vertices for some small *n*. Indeed, the only tree that maximizes $Epr[D(Tr)]$ for *n* ≤ 2 are the one-vertex tree and the two-vertex tree, which are both star trees.

*n*≥ 3, it suffices to prove that

*L*(

*n*,

*d*

_{r}). Applying the induction hypothesis (each maximum subtree of a tree of

*n*vertices is a star tree), we have that

*n*

_{i}≥ 2, such that the sum of squared components is strictly larger while the sum of the components remains constant. Therefore, the maximum sum of squares is obtained by choosing $ndr=n\u2212dr$ and

*n*

_{i}= 1 for 1 ≤

*i*<

*d*

_{r}, yielding

*d*to the left-hand side we obtain

*d*

_{r}=

*n*− 2. Because this last inequality holds true when

*n*> 5/2, we are done.

It is easy to see that $Epr[D(Tr)]$ is bounded above by the expected value of *D*(*T*) as stated in Corollary 1 and justified in its proof below.

*Proof of Corollary 1 (stated on page 495).*

Because of Theorem 2, the maximum value of $Epr[D(Tr)]$ is maximized by $Snh$, formally $Epr[D(Tr)]\u2264Epr[D(Snh)]$, which, in turn, becomes $Epr[D(Snh)]=(n2\u22121)/3$, as shown in Table 1. Finally, recall that $E[D(T)]=(n2\u22121)/3$ (Equation (4)), and thus $Epr[D(Snh)]=E[D(T)]$.

*n*, the number of vertices, and

*H*a hash table whose keys are natural numbers

*k*and the value associated with each key is a pair formed by

*f*

_{m}(

*k*) and the

*k*-vertex trees

*T*

^{r}that attain that

*f*

_{m}(

*k*). Notice that

*n*is an input parameter, while

*H*is an input/output parameter. In order to calculate the minimum

*n*-vertex trees, the values of the parameters of the first call to Algorithm 1 are the value

*n*and an empty

*H*. Now, Algorithm 1 is a direct evaluation of Equation (40), that is, for every value of out-degree of the root

*d*

_{r}(1 ≤

*d*

_{r}≤

*n*− 1), it computes the value

*f*

_{m}(

*n*) by finding the partition of

*n*− 1 into

*d*summands that minimizes

*f*

_{m}(

*n*

_{i}) is calculated recursively and stored in the hash table

*H*. Therefore, the algorithm’s complexity heavily depends on the number of partitions of

*n*− 1, denoted as

*p*(

*n*− 1). The worst-case complexity of Algorithm 1, then, is superpolynomial in

*n*due to the exponential nature of

*p*(

*n*) (Hardy and Ramanujan 1918). Finally, notice that the “Modified Cartesian” product in line 19 of Algorithm 1 must ensure that no repeated trees are produced. Repeated trees arise in the standard Cartesian product due to the fact that some partitions may have repeated parts. As an example, consider the partition of 37 with two repeated parts (11,13,13); such parts have 1 and 2 non-isomorphic minimum trees, respectively (Figure 7). Let

*t*

_{11}= {

*T*

_{A}} be the unique 11-vertex minimum tree, and

*t*

_{13}= {

*T*

_{B},

*T*

_{C}} be the two 13-vertex minimum trees. The Cartesian product

*t*

_{11}×

*t*

_{13}×

*t*

_{13}produces four forests, two of them being isomorphic: (

*T*

_{A},

*T*

_{B},

*T*

_{C}) and (

*T*

_{A},

*T*

_{C},

*T*

_{B}); the other two forests are (

*T*

_{A},

*T*

_{B},

*T*

_{B}) and (

*T*

_{A},

*T*

_{C},

*T*

_{C}). In order to obtain the unique

*n*-vertex trees (up to isomorphism) that attain

*f*

_{m}(

*n*), we modify the standard Cartesian product. Let {

*T*

^{*}}

^{(i)}be the list of

*n*

_{i}-vertex minimum trees. Thus, one element in the Cartesian product is obtained by choosing the trees in the

*j*

_{1}th, ⋯, $jdr$th positions of the lists, that is,

*j*

_{i}≤|{

*T*

^{*}}

^{(i)}| for all

*i*∈ [1,

*d*

_{r}]. Now, tree uniqueness is ensured by forcing indices of every pair of lists {

*T*

^{*}}

^{(i)},{

*T*

^{*}}

^{(i +1)}such that

*n*

_{i}=

*n*

_{i +1}is

*j*

_{i}≤

*j*

_{i +1}.

In this article, we do not characterize the minima of $Epr[D(Tr)]$ because, unlike the number of maxima, which shows a clear regularity, the number of minima varies with *n* in a non-monotonic fashion. Table 2 shows that the number of these minima oscillates between 1 and 2 for *n* ≤ 20 and Figure 6 shows the number of minimum trees in linear-log scale for *n* ≤ 178. Figure 7 suggests that the shape of the trees does not seem to fit into a simple class. Moreover, Figure 8 shows the values of *f*_{m}(*n*) in log-linear scale. The straight line that is found in that scale for sufficiently large *n* suggests $fm(n)=O(nlogn)$ asymptotic behavior, to be confirmed in future research.

**Table 2**

n
. | # trees . | # opt trees . | $Epr[D(Tr)]$ . | n
. | # trees . | # opt trees . | $Epr[D(Tr)]$ . |
---|---|---|---|---|---|---|---|

1 | 1 | 1 | 0 | 11 | 1,842 | 1 | 22 |

2 | 1 | 1 | 1 | 12 | 4,766 | 1 | $25.16\xaf$ |

3 | 1 | 1 | 2.5 | 13 | 12,486 | 2 | $28.3\xaf$ |

4 | 4 | 2 | 4.5 | 14 | 32,973 | 1 | 31.5 |

5 | 9 | 1 | $6.3\xaf$ | 15 | 87,811 | 1 | $34.6\xaf$ |

6 | 20 | 1 | $8.6\xaf$ | 16 | 235,381 | 1 | 38 |

7 | 48 | 1 | 11 | 17 | 634,847 | 1 | 41.5 |

8 | 115 | 2 | $13.83\xaf$ | 18 | 1,721,159 | 2 | 45 |

9 | 286 | 1 | 16.5 | 19 | 4,688,676 | 2 | 48.5 |

10 | 719 | 2 | $19.3\xaf$ | 20 | 12,826,228 | 2 | 52 |

n
. | # trees . | # opt trees . | $Epr[D(Tr)]$ . | n
. | # trees . | # opt trees . | $Epr[D(Tr)]$ . |
---|---|---|---|---|---|---|---|

1 | 1 | 1 | 0 | 11 | 1,842 | 1 | 22 |

2 | 1 | 1 | 1 | 12 | 4,766 | 1 | $25.16\xaf$ |

3 | 1 | 1 | 2.5 | 13 | 12,486 | 2 | $28.3\xaf$ |

4 | 4 | 2 | 4.5 | 14 | 32,973 | 1 | 31.5 |

5 | 9 | 1 | $6.3\xaf$ | 15 | 87,811 | 1 | $34.6\xaf$ |

6 | 20 | 1 | $8.6\xaf$ | 16 | 235,381 | 1 | 38 |

7 | 48 | 1 | 11 | 17 | 634,847 | 1 | 41.5 |

8 | 115 | 2 | $13.83\xaf$ | 18 | 1,721,159 | 2 | 45 |

9 | 286 | 1 | 16.5 | 19 | 4,688,676 | 2 | 48.5 |

10 | 719 | 2 | $19.3\xaf$ | 20 | 12,826,228 | 2 | 52 |

## 4 Exact versus Approximate Calculation of the Expected Sum of Dependency Distances

*D*under projectivity has been estimated with a Monte Carlo approximation method

^{2}(Gildea and Temperley 2007; Park and Levy 2009; Gildea and Temperley 2010; Futrell, Mahowald, and Gibson 2015; Kramer 2021) whose cost

*O*(

*Rn*), where

*R*is the number of random arrangements sampled and

*O*(

*n*) is the cost of generating a random arrangement and computing

*D*on it. Our method, as well as providing exact values, has a much lower complexity

*O*(

*n*) as there is no need for random sampling. We used the

*UD2.5*(de Marneffe et al. 2019) treebanks for Catalan, English, and German to measure the relative error of the Monte Carlo approximation method for values of

*R*used in past research. English and German are selected because they have been used in previous research utilizing projective random baselines (Gildea and Temperley 2007; Park and Levy 2009; Gildea and Temperley 2010). Catalan is included as the native language of the present authors. For each sentence

*T*

^{r}in a treebank, we calculated $Epr[D(Tr)]$ in two ways. First, exactly with Equation (6). Second, approximately by averaging the value of

*D*obtained in

*R*= 10

^{i}, for 1 ≤

*i*≤ 4, uniformly random projective arrangements (denoted as $E~pr[D(Tr)]$). More precisely, given ${\pi i}i=1R$ random projective arrangements of a given rooted tree,

_{rel}(

*T*

^{r}) for every tree as

_{rel}(

*T*

^{r}) > 0 indicates that $E~pr[D(Tr)]$ overestimates $Epr[D(Tr)]$; ε

_{rel}(

*T*

^{r}) < 0 indicates underestimation error. Figure 9 shows the average, minimum, maximum, and confidence interval of the relative error as a function of sentence length (see the Appendix for a parallel analysis of the standard deviation of

*D*(

*T*

^{r})). This figure can be seen as a confirmation of the correctness of Theorem 1 via simulation.

In previous research, the value of *R* is sometimes indicated, for example, *R* = 10 (Kramer 2021) and *R* = 100 (Futrell, Mahowald, and Gibson 2015), and sometimes not reported (Park and Levy 2009; Gildea and Temperley 2010). When *R* = 10, Figure 9 shows that the relative error peaks between *n* = 10 and *n* = 20 (close to the mean sentence length in English [Rudnicka 2018]) and tends to decay from then onward. However, the confidence interval of the relative error clearly broadens for sufficiently large *n*, for example, *n* = 30 or *n* = 40 onward. These behaviors smooth out for *R* = 100 while the range of variation and the confidence interval are narrower. As expected, the relative error reduces dramatically for larger *R*. In sum, Figure 9 indicates that a large *R* must be used to estimate $Epr[D(Tr)]$ with high numerical precision. However, that increases the computation time. An implication of that figure is that the best solution in terms of numerical precision and speed is provided by Equation (31).

## 5 Conclusions and Future Work

In this article, we have derived several simple closed-form formulae related to projective arrangements of rooted trees in Section 2. First, we have given a simple closed-form formula to calculate the number of *different* projective arrangements a rooted tree admits, **N**_{pr}(*T*^{r}) (Proposition 1). The proof reveals a straightforward way of enumerating such arrangements for an input rooted tree, and of generating this kind of arrangement uniformly at random without a rejection method. Second, and more importantly, we have provided a way of calculating, for any given rooted tree, the expected value of the sum of edge lengths over the space of uniformly random *different* projective arrangements, $Epr[D(Tr)]$ (Theorem 1 and Corollary 2). This means that future studies in which such value is calculated approximately via random sampling of arrangements can now be calculated exactly and much faster. The *O*(*Rn*) Monte Carlo method to estimate true expectation with an error that tends to zero as *R* tends to infinity can now be replaced by our fast *O*(*n*) with zero error. Moreover, these formulae can be instantiated in particular classes of trees (as shown in Section 2.4). In Section 3, we have characterized the trees that maximize $Epr[D(Tr)]$ and proven that there exists a dynamic programming method to calculate the minima of $Epr[D(Tr)]$. A precise characterization of the minima should be the subject of future research. Finally, in Section 4 we have highlighted the obvious advantages of an exact and fast calculation of $Epr[D(Tr)]$ for future quantitative dependency syntax research.

The present article is part of a research program on the calculation of random baselines for *D* via formulae or exact algorithms under formal constraints on linear arrangements that started about two decades ago with the unconstrained case, for example Equation (4) (Zörnig 1984; Ferrer-i-Cancho 2004). Here we have covered the projective case. In a forthcoming article, we will focus on planar linearizations of (free) trees—those in which there are no edge crossings—and obtain a closed-form formula, and a *O*(*n*)-time algorithm, to calculate $Epl[D(T)]$, the expected value of *D*(*T*) in uniformly random planar arrangements of a given (labeled free) tree *T* (Alemany-Puig and Ferrer-i-Cancho 2022). In the future, the problem of the calculation of the variance of *D*(*T*^{r}) in random projective arrangements should also be considered. The analysis of the distribution of dependency distances—for example, their first and second moments of *D*(*T*^{r}), in random arrangements that are not uniformly random (but still projective and planar)—could benefit from applying general-purpose algorithmic frameworks (Eisner 2002; Li and Eisner 2009; Wang and Eisner 2018).

*Ω*(

*T*), which is defined with respect to the minimum and random baseline in unconstrained linear arrangements.

*Ω*(

*T*) is defined as (Ferrer-i-Cancho et al. 2022)

*m*[

*D*(

*T*)] is the minimum

*D*

_{π}(

*T*) over all unconstrained linear arrangements π, known as the Minimum Linear Arrangement problem (Garey, Johnson, and Stockmeyer 1976; Shiloach 1979; Chung 1984). However, projectivity is the most widely used constraint to investigate dependency distances and to define the corresponding minimum and random baselines (Futrell, Mahowald, and Gibson 2015; Gulordava and Merlo 2015; Futrell, Levy, and Gibson 2020). With the result in Theorem 1, one could replicate the aforementioned study under the projectivity constraint by redefining the score as

*m*

_{pr}[

*D*(

*T*

^{r})] (Hochberg and Stallmann 2003; Gildea and Temperley 2007), and is linear-time computable (Alemany-Puig, Esteban, and Ferrer-i-Cancho 2022). While

*Ω*(

*T*) ≤ 1 holds for any sentence (Ferrer-i-Cancho et al. 2022), as it is equivalent to

*D*(

*T*) ≥

*m*[

*D*(

*T*)], the statement

*Ω*

_{pr}(

*T*

^{r}) ≤ 1 only holds when applied to projective sentences. In other words,

*Ω*

_{pr}(

*T*

^{r}) ≤ 1 needs not hold because we can have that

*D*(

*T*

^{r}) >

*m*

_{pr}[

*D*(

*T*

^{r})]. In the absence of any word order constraint on a sentence,

*Ω*is expected to be zero while

*Ω*

_{pr}(

*T*

^{r}) is expected to be zero if the only word order constraint is projectivity. Formally, $E[\Omega (T)]=0$ and $Epr[\Omega pr(Tr)]=0$. Thanks to our article, such investigation of the optimality of dependency distances can be carried out, reducing the computational cost and maximizing numerical precision with respect to an approach based on a Monte Carlo estimation of $Epr[D(Tr)]$.

Here we have focused on $Epr[D(Tr)]$, the expectation of *D*(*T*^{r}) on random arrangements of an individual tree. Finally, future research should consider the problem of $E[Epr[D]]$, the expectation of $Epr[D]$ on ensembles of random trees of a fixed size *n*. $E[Epr[D]]$ is indeed the average value of $Epr[D(Tr)]$ among all *n*-vertex rooted trees *T*^{r}. Although there are at least two ensembles possible, that is, uniformly random *labeled* trees and uniformly random *unlabeled* trees, a closed-form formula (or algorithm) to calculate $E[Epr[D]]$ seems easier to obtain in the former.

## Acknowledgments

We are thankful to the anonymous reviewers for invaluable comments and suggestions. LAP is supported by Secretaria d’Universitats i Recerca de la Generalitat de Catalunya and the Social European Fund. RFC is also supported by the recognition 2017SGR-856 (MACDA) from AGAUR (Generalitat de Catalunya). RFC and LAP are supported by the grant TIN2017-89244-R from MINECO (Ministerio de Economía, Industria y Competitividad).

## Appendix A. The Standard Deviation of **D**(**T**^{R}) in Projective Arrangements

*σ*(

*T*

^{r}) of

*D*

_{π}(

*T*

^{r}) over

*R*random projective arrangements π via

*σ*is calculated using $Epr[D(Tr)]$ and not $E~pr[D(Tr)]$. Figure A.1 shows that

*σ*increases with

*n*(as expected) but that it does not decrease as

*R*increases; furthermore, the apparent linear trend for sufficiently large

*n*suggests an

*O*(

*n*) growth of

*σ*, to be confirmed in future research.

## Notes

Alternatively, an *n*-vertex quasi-star tree is obtained by joining to a 2-vertex complete graph, *K*_{2}, a pendant vertex to one end and *n* − 3 pendant vertices to the other end of *K*_{2}; a quasi-star tree is a particular case of bistar tree (San Diego and Gella 2014).

This Monte Carlo method consists of averaging the values of *D* obtained via random sampling of *R* random projective arrangements of a rooted tree. It is well known that the error of such methods decreases as the number of samples increases.

## References

*The Syntax of German-English Code-Switching*

*b*-chromatic number of bistar graph

## Author notes

Action Editor: Giorgo Satta