Subquadratic-time algorithm for the diameter and all eccentricities on median graphs

On sparse graphs, Roditty and Williams [2013] proved that no $O(n^{2-\varepsilon})$-time algorithm achieves an approximation factor smaller than $\frac{3}{2}$ for the diameter problem unless SETH fails. In this article, we solve an open question formulated in the literature: can we use the structural properties of median graphs to break this global quadratic barrier? We propose the first combinatiorial algorithm computing exactly all eccentricities of a median graph in truly subquadratic time. Median graphs constitute the family of graphs which is the most studied in metric graph theory because their structure represents many other discrete and geometric concepts, such as CAT(0) cube complexes. Our result generalizes a recent one, stating that there is a linear-time algorithm for all eccentricities in median graphs with bounded dimension $d$, i.e. the dimension of the largest induced hypercube. This prerequisite on $d$ is not necessarily anymore to determine all eccentricities in subquadratic time. The execution time of our algorithm is $O(n^{1.6408}\log^{O(1)} n)$. We provide also some satellite outcomes related to this general result. In particular, restricted to simplex graphs, this algorithm enumerates all eccentricities with a quasilinear running time. Moreover, an algorithm is proposed to compute exactly all reach centralities in time $O(2^{3d}n\log^{O(1)}n)$.


Introduction
Median graphs can be certainly identified as the most important family of graphs in metric graph theory. They are related to numerous areas: universal algebra [3,16], CAT(0) cube complexes [5,20], abstract models of concurrency [11,37], and genetics [8,10]. Let d(a, b) be the length (i.e. the number of edges) of the shortest (a, b)-path for a, b ∈ V and I(a, b) be the set made up of all vertices u metrically between a and b, i.e. d(a, b) = d(a, u) + d (u, b). Median graphs are the graphs such that for any triplet of distinct vertices x, y, z ∈ V , set I(x, y) ∩ I(y, z) ∩ I(z, x) is a singleton, containing the median m(x, y, z) of this triplet. The purpose of this article is to break the quadratic barrier for the computation time of certain metric parameters on median graphs. In particular, we focus on one of the most fundamental problems in algorithmic graph theory related to distances: the diameter. Given an undirected graph G = (V, E), the diameter is the maximum distance d (u, v) for all u, v ∈ V . Two vertices at maximum distance form a diametral pair. An even more general problem consists in determining all eccentricities of the graph. The eccentricity ecc(v) of a vertex v is the maximum length of a shortest path starting from v: ecc(v) = max w∈V d (v, w). The diameter is thus the maximum eccentricity.

State of the art
Executing a Breadth First Search (BFS) from each vertex of an input graph G suffices to obtain its eccentricities in O(n |E|), with n = |V |. As median graphs are relatively sparse, |E| ≤ n log n, these multiple BFSs compute all eccentricities in time O(n 2 log n) for this class of graphs. Very efficient algorithms determining the diameter already exist on other classes of graphs, for example [2,18,24]. Many works have also been devoted to approximation algorithms for this parameter. Chechik et al. [19] showed that the diameter can be approximated within a factor 3 2 in timeÕ(m 3 2 ) on general graphs. On sparse graphs, it was shown in [36] that no O(n 2−ε )-time algorithm achieves an approximation factor smaller than 3 2 for the diameter unless the Strong Exponential Time Hypothesis (SETH) fails. Median graphs are bipartite and can be isometrically embedded into hypercubes. They are the 1-skeletons of CAT(0) cube complexes [20] and the domains of event structures [11]. They admit structural properties, such as the Mulder's convex expansion [34,35]. They are strongly related to hypercubes retracts [4], Cartesian products and gated amalgams [5], but also Helly hypergraphs [33]. They do not contain induced K 2,3 , otherwise a triplet of vertices would admit at least two medians. The dimension d of a median graph G is the dimension of its largest induced hypercube. The value of this parameter is at most ⌊log n⌋ and meets this upper bound when G is a hypercube. Moreover, parameter d takes part in the sparsity of median graphs: |E| ≤ dn.
An important concept related to median graphs is the equivalence relation Θ. This is the reflexive and transitive closure of relation Θ 0 , where two edges are in Θ 0 if they are opposite in a common 4-cycle. A Θ-class is an equivalence class of Θ. Each Θ-class of a median graph forms a matching cutset, splitting the graph into two convex connected components, called halfspaces. The number q ≤ n of Θ-classes corresponds to the dimension of the hypercube in which the median graph G isometrically embeds. Value q satisfies the Euler-type formula 2n − m − q ≤ 2 [29]. A recent LexBFS-based algorithm [13] identifies the Θ-classes in linear time O(|E|) = O(dn).
There exist efficient algorithms for some metric parameters on median graphs. For example, the median set and the Wiener index can be determined in O(|E|) [13]. Subfamilies of median graphs have also been studied. There is an algorithm computing the diameter and the radius in linear time for squaregraphs [21]. A more recent contribution introduces a quasilinear time algorithm -running in O(n log O(1) n) -for the diameter on cube-free median graphs [23], using distance and routing labeling schemes proposed in [22]. Eventually, a linear-time algorithm [15] for the diameter on constant-dimension median graphs was proposed, i.e. for median graphs satisfying d = O (1).
The existence of a truly subquadratic-time algorithm for the diameter on all median graphs is open and was recently formulated in [13,15,23]. An even more ambitious question can be asked. Can this subquadratic barrier be overpassed for the problem of finding all eccentricities of a median graph ? As the total size of the output is linear and this problem generalizes the diameter one, this question is legitimate. More generally, the question holds for all metric parameters (except the median set and the Wiener index for which a linear-time algorithm was recently designed). We propose here the first subquadratic-time algorithm computing all eccentricities on median graphs.

Contributions
Our first contribution in this paper is the design of a quasilinear, i.e. O((log n) O(1) n), time algorithm computing the diameter of simplex graphs. A simplex graph K(G) = (V K , E K ) of a graph G is obtained by considering the induced complete graphs (cliques) of G as vertices V K . Then, two of these cliques are connected by an edge if they differ by only one element: one is C, the other is C ∪ {v}. These edges form the set E K . All simplex graphs are median [5,12]. Moreover, we observe that simplex graphs fulfil an interesting property: they admit a central vertex -representing the empty clique -and every Θ-class has an edge incident to that vertex.
First, this algorithm extends the set of median graphs for which a quasilinear time procedure computing the diameter exists. Indeed, simplex graphs form a sub-class of median graphs containing instances with unbounded dimension d.
There is a combinatorial algorithm determining the diameter and all eccentricities of simplex graphs in O((d 3 + log n)n): Theorem 3.8, Section 3.
Second, we remark that this method can be integrated to the algorithm already proposed in [15] to compute all eccentricities of median graphs in time O(2 O(d log d) n). This allows us to decrease this running time. Thanks to this modification, the new algorithm proposed computes all eccentricities of a median graph inÕ(2 2d n), where notationÕ neglects polylogarithmic factors. Even if the algorithm stays linear for constant-dimension median graphs, observe that the dependence on d decreases, from a slightly super-exponential function to a simple exponential one.
There is a combinatorial algorithm determining all eccentricities of median graphs iñ O(2 2d n): Theorem 4.16, Section 4.1.
The second and main contribution in this paper is the design of a subquadratic-time dynamic programming procedure which computes all eccentricities of any median graph. Here, the linear-time simple-exponential-FPT algorithm for all eccentricities presented above plays a crucial role: it is the base case. This framework consists in partitioning recursively the input graph G into the halfspaces of its largest Θ-class. With our construction, the leaves of this recursive tree are median graphs with dimension at most ⌊ 1 3 log n⌋ and we can apply the former linear-time FPT algorithm.
There is a combinatorial algorithm determining all eccentricities of median graphs iñ O(n We terminate by mentioning a possible improvement of this algorithm. Based on a faster enumeration of sets of pairwise orthogonal Θ-classes, its running time can be decreased tõ O(n β ), where β = 1.6456. Due to page limit, this extra part is omitted. A long version of this paper presents this result [14].
All these outcomes put in evidence a relationship between the design of linear-time FPT algorithms and the design of subquadratic-time algorithms determining metric parameters on median graphs. We hope that the ideas proposed to establish all these results represent interesting tools to break the quadratic barrier on other open questions.

Organization
In Section 2, we remind the definition of median graphs. The well-known properties and concepts related to them are listed, among them Θ-classes, signature, and POFs. Section 3 summarizes our contribution on simplex graphs. In Section 4, we show how to obtain a lineartime simple-exponential-FPT algorithm for all eccentricities of a median graph, parameterized ▶ Definition 2.1 (Median graph). A graph is median if, for any triplet x, y, z of distinct vertices, the set I(x, y) ∩ I(y, z) ∩ I(z, x) contains exactly one vertex m(x, y, z) called the median of x, y, z.
Observe that certain well-known families of graphs are median: trees, grids, squaregraphs [7], and hypercubes Q k . Median graphs are bipartite and do not contain an induced K 2,3 [5,26,34]. They can be obtained by Mulder's convex expansion [34,35] starting from a single vertex. Now, we define a parameter which has a strong influence on the study of median graphs. The dimension d = dim(G) of a median graph G is the dimension of the largest hypercube contained in G as an induced subgraph. In other words, G admits Q d as an induced subgraph, but not Q d+1 . Median graphs with d = 1 are exactly the trees. Median graphs with d ≤ 2 are called cube-free median graphs. Figure 1 presents three examples of median graphs. (a) is a tree: d = 1. (b) is a cube-free median graph: it has dimension d = 2. To be more precise, it is a squaregraph [7], which is a sub-family of cube-free median graphs. The last one (c) is a 4-cube: it has dimension d = 4.  We provide a list of properties satisfied by median graphs. In particular, we define the notion of Θ-classes which is a key ingredient of several existing algorithms [13,25,27].
In general graphs, all gated subgraphs are convex. The reverse is true in median graphs.
To improve readibility, edges (u, v) ∈ E are sometimes denoted by uv. We remind the notion of Θ-class, which is well explained in [13], and enumerate some properties related to it. We say that the edges uv and xy are in relation Θ 0 if they form a square uvyx, where uv and xy are opposite edges. Then, Θ refers to the reflexive and transitive closure of relation Θ 0 . Let q be the number of equivalence classes obtained with this relation. The classes of the equivalence relation Θ are denoted by E 1 , . . . , E q . Concretely, two edges uv and u ′ v ′ belong to the same Θ-class if there is a sequence uv are opposite edges of a square. We denote by E the set of Θ-classes: E = {E 1 , . . . , E q }. To avoid confusions, let us highlight that parameter q is different from the dimension d: for example, on trees, d = 1 whereas q = n − 1. Moreover, the dimension d is at most ⌊log n⌋ in general. In median graphs, each class E i , 1 ≤ i ≤ q, is a perfect matching cutset and its two sides H ′ i and H ′′ i verify nice properties, that are presented below.
As a consequence, suppose uv and u ′ v ′ belong to E i : if uu ′ is an edge and belongs to class E j , then vv ′ is an edge too and it belongs to E j . We terminate this list of lemmas with a last property dealing with the orientation of edges from a canonical basepoint v 0 ∈ V . The v 0 -orientation of the edges of G according to v 0 is such that, for any edge uv, the orientation ▶ Lemma 2.6 (Orientation [13]). All edges can be oriented according to any canonical basepoint v 0 .
From now on, we suppose that an arbitrary basepoint v 0 ∈ V has been selected and we refer automatically to the v 0 -orientation when we mention incoming or outgoing edges.

Shortest paths and signature
We fix an arbitrary canonical basepoint v 0 and for each class E i , we say that the halfspace containing v 0 is H ′ i . Given two vertices u, v ∈ V , we define the set which contains the Θ-classes separating u from v. ▶ Definition 2.7 (Signature σ u,v ). We say that the signature of the pair of vertices u, v, denoted by σ u,v , is the set of classes E i such that u and v are separated in G\E i . In other words, u and v are in different halfspaces of E i .
The signature of two vertices provide us with the composition of any shortest (u, v)-path. Indeed, all shortest (u, v)-paths contain exactly one edge for each class in σ u,v .
▶ Lemma 2.8 ([15]). For any shortest (u, v)-path P , the edges in P belong to classes in σ u,v and, for any E i ∈ σ u,v , there is exactly one edge of E i in path P . Conversely, a path containing at most one edge of each Θ-class is a shortest path between its departure and its arrival.
This result is a direct consequence of the convexity of halfspaces. By contradiction, a shortest path that would pass through two edges of some Θ-class E i would escape temporarily from an halfspace, say w.l.o.g H ′ i , which is convex (Lemma 2.4). Definition 2.7 can be generalized: given a set of edges B ⊆ E, its signature is the set of Θ-classes represented in that set: The signature of a path is the set of classes which have at least one edge in this path. In this way, the signature σ u,v is also the signature of any shortest (u, v)-path. The signature of a hypercube is the set of Θ-classes represented in its edges: the cardinality of the signature is thus equal to the dimension of the hypercube.

Orthogonal Θ-classes and hypercubes
We present now another important notion on median graphs: orthogonality.
▶ Definition 2.9 (Orthogonal Θ-classes). We say that classes E i and E j are orthogonal We say that E i and E j are parallel if they are not orthogonal, that is We define the sets of pairwise orthogonal Θ-classes.
▶ Definition 2.10 (Pairwise Orthogonal Family). We say that a set of classes For any induced hypercube of G, its basis (resp. anti-basis) is the closest vertex (resp. farthest) to v 0 in it. All edges of the hypercube indicent to the basis are outgoing from it in the v 0 -orientation. Hypercubes are in bijection with pairs (u, L), where u is a vertex (the basis of the hypercube) and L is a POF outgoing from u (the signature of the hypercube).
The full version of this subsection is put in Appendix A.

Simplex graphs
Due to page limit, the proofs in this Section are omitted. Given any undirected graph G, the vertices of the simplex graph K(G) associated to G represent the induced cliques (not necessarily maximal) of G. Two of these cliques are connected by an edge if they differ by exactly one element.
▶ Definition 3.1 (Simplex graphs [9]). The simplex graph Simplex graphs can be characterized as particular median graphs.
▶ Theorem 3.2. Let G be a median graph. The following statements are equivalent: In this section only, on simplex graphs, the canonical basepoint v 0 is not selected arbitrarily. We fix v 0 as a vertex adjacent to all Θ-classes, as put in evidence by Theorem 3.2. We call v 0 the central vertex of the simplex graph.
▶ Definition 3.3 (Crossing graphs [9,28]). Let G be a median graph. Its crossing graph G # is the graph obtained by considering Θ-classes as its vertices and such that two Θ-classes are adjacent if they are orthogonal.
Restricted to simplex graphs, this transformation is the reverse of K: indeed, as stated in [28], G = K(G) # . The clique number of G # is exactly the dimension of median graph G. For example, the crossing graph of a cube-free median graph contains no triangle. Each simplex graph admits a central vertex (v 0 in Theorem 3.2) which represents the empty clique of G # . Now, we focus on the problem of determining a diametral pair of a simplex graph G and more generally all eccentricities. Observe that the distance between the central vertex v 0 and any vertex u of G can be deduced directly from the set E − (u) of Θ-classes incoming into u. We state that σ v0,u = E − (u). This is a consequence of Theorem 3.2: all Θ-classes of E − (u) are adjacent to v 0 , so v 0 is the basis of the hypercube with signature E − (u) and anti-basis u.
A key result is the fact that the central vertex v 0 of the simplex graph belongs to the interval Two vertices u, v forming a diametral pair cannot share a common incoming Θ-class . So, determining the diameter of a simplex graph G is equivalent to maximizing the sum |X| + |Y |, where X and Y are two POFs of G that are disjoint. Computing the diameter is equivalent to find the largest pair of disjoint cliques in the crossing graph G # . Similarly, the eccentricity of a vertex u is exactly the size ). Now, we can define the notion of opposite.
▶ Definition 3.5. Let G be a simplex graph and X a POF of G. We denote by op(X) the opposite of X, i.e. the POF Y disjoint from X with the maximum cardinality.
With this definition, the eccentricity of a vertex u, if we fix X u = E − (u), is written ecc(u) = |X u | + |op(X u )|. Hence, the diameter of the simplex graph G can be written as the size of the largest pair POF-opposite: diam(G) = max X∈L (|X| + |op(X)|).
We propose now the definition of two problems on simplex graphs. The first one, called Opposites (OPP) consists in finding all pairs POF-opposite. Its output has thus a linear size. Given the solution of OPP on graph G, one can deduce both the diameter and all eccentricities in O(n) time with the formula: ecc(u) = |X u | + |op(X u )|.
Input: Simplex graph G, central vertex v 0 . Output: For each POF X, its opposite op(X).
We define an even larger version of the problem where a positive integer weight is associated with each POF. We call it Weighted Opposites (WOPP).

▶ Definition 3.7 (WOPP).
Input: Obviously, OPP is a special case of WOPP when ω is the cardinality function. We show that WOPP can be solved in quasilinear time O((d 3 + log n)n), as d ≤ ⌊log n⌋. As a consequence, all eccentricities of a simplex graph G can also be determined with such time complexity.
▶ Theorem 3.8. There is a combinatorial algorithm solving WOPP in time O((d 3 + log n)n). Consequently, it determines all eccentricities of a simplex graph with this running time.

Subquadratic-time algorithm for all eccentricities on median graphs
This section introduces the design of algorithms computing all eccentricities for the whole class of median graphs (not only simplex graphs). We begin in Section 4.1 with the proposal of a linear-time FPT algorithm, parameterized by the dimension d, running in 2 O(d) n. It is based on some techniques of a paper of the literature [15] which provides a slightly superexponential time algorithm -running in 2 O(d log d) n -for the same problem. We prove that replacing one step of this procedure by the partitioning conceived in Section 3 allows us to decrease the exponential dependence on d.
Thanks to this outcome, in Section 4.2, we are able to design a first subquadratic-time algorithm for all median graphs running inÕ(n

Linear FPT algorithm for constant-dimension median graphs
We remind in this subsection the different steps needed to obtain a linear-time algorithm computing all eccentricities of a median graph with constant dimension, d = O(1). We show how Theorem 3.8 can be integrated to it in order to improve the dependence on d. Let us begin with a reminder of the former result.
Some parts of this subsection are redundant with [15], however we keep this subsection self-contained. The new outcomes presented are Theorems 4.10 and 4.16.
The algorithm evoked by Lemma 4.1 consists in the computation of three kinds of labels: ladder labels φ, opposite labels op and anti-ladder labels ψ. The order in which they are given correspond to their respective dependence: op-labelings are functions of labels φ and ψ-labelings are functions of both labels φ and op. The definition of op-labelings on general median graphs is closely related to the computation of eccentricities on simplex graphs evoked in Section 3.

Ladder labels
Some preliminary work has to be done before giving the definition of labels φ. We introduce the notion of ladder set. It is defined only for pairs of vertices u, v satisfying the condition u ∈ I(v 0 , v). In this situation, the edges of shortest (u, v)-paths are all oriented towards v with the v 0 -orientation.  A key characterization on ladder sets states that their Θ-classes are pairwise orthogonal. In brief, every set L u,v is a POF. Let us remind that the adjacency of all Θ-classes of a POF L with the same vertex u implies the existence of a (unique) hypercube not only signed with this POF L but also containing u (Lemma A.5). If additionnally POF L is outgoing from u -said differently, the edges adjacent to u belonging to a Θ-class of L leave u -, then u is the basis of the hypercube. As the Θ-classes of L u,v are adjacent to u by definition, there is a natural bijection between (i) hypercubes (ii) pairs made up of a vertex u and a POF L outgoing from u and (iii) pairs vertex-ladder set (u, L u,· ).
S TA C S 2 0 2 2 9:10 All Eccentricities on Median Graphs in Subquadratic Time The necessary background to introduce labels φ is now known.
▶ Definition 4.4 (Labels φ [15]). Given a vertex u and a POF L outgoing from u, let φ(u, L) be the maximum distance d(u, v) such that u ∈ I(v 0 , v) and L u,v = L.
Intuitively, integer φ(u, L) provides us with the maximum length of a shortest path starting from u into "direction" L. Observe that the total size of labels φ on a median graph G does not exceed O(2 d n), according to Lemma A.7. We provide another notion related to orthogonality which will be used in the remainder.

▶ Definition 4.5 (L-parallelism). We say that a POF
When L ′ is a L-parallel POF, we have L ∩ L ′ = ∅, otherwise L ∪ {E j } = L for some E j ∈ L ′ . Presented differently, a L-parallel POF is such that any of its Θ-classes is parallel to at least one Θ-class of L.
A combinatorial algorithm running inÕ(2 2d n) which computes all labels φ(u, L) was identified in [15]: we provide an overview of it. There is a crucial relationship between a label φ(u, L) and the labels of (i) the anti-basis u + of the hypercube with basis u and signature L and (ii) the L-parallel POFs outgoing from u + . ▶ Lemma 4.6 (Inductive formula for labels φ [15]). Let u ∈ V , L be a POF outgoing from u and Q be the hypercube with basis u and signature L. We denote by u + the opposite vertex of u in Q: u is the basis of Q and u + its anti-basis.
A consequence of the previous lemma is that we can distinguish two cases for the computation of φ(u, L). In the first case, φ(u, L) = |L|: it occurs when the farthest-to-u vertex with ladder set L is u + (base case). Indeed, u + is a candidate as σ u,u + = L: shortest (u, u + )-paths pass through hypercube Q. This situation happens when either no Θ-class is outgoing from u + or when all Θ-classes outgoing from u + are orthogonal to L. In the second case, there are vertices farther to u than u + with ladder set L. As announced in Lemma 4.6, φ(u, L) is a function of labels φ(u + , ·).
If there exists such a POF L + , then the label φ(u, L) is given by Equation (1). Otherwise, it is given by the first case. Briefly, the algorithm consists in listing all pairs vertex-ladder set ((u, L), (u + , L + )) such that u + is the anti-basis of the hypercube of basis u and signature L. For each of it, we verify whether L + is L-parallel. If it is, we update φ(u, L) if |L| + φ(u + , L + ) is greater than the current value. The total number of pairs ((u, L), (u + , L + )) is upperbounded by 2 2d n: there are at most 2 d n pairs (u + , L + ) (bijection with hypercubes) and, for each of them, there are at most 2 d compatible pair (u, L) such that u + is the anti-basis of (u, L). Indeed, the number of edges incoming into u + is at most d (Lemma A.6). For this reason, the computation of φ-labelings takesÕ(2 2d n).

Opposite labels
The second type of labels needed to compute all eccentricities of a median graph G are opposite labels. Given a vertex u and a POF L outgoing from u, let op u (L) denote a POF outgoing from u with maximum label φ which is disjoint from L. As for φ, the total size of op-labelings is O(2 d n).
▶ Definition 4.8 (Labels op [15]). Let u ∈ V and L be a POF outgoing from u. Let op u (L) be one of the POF L ′ outgoing from u, disjoint from L, which maximizes value φ(u, L ′ ).
On simplex graphs, the opposite function provides in fact the op-labelings of vertex v 0 : op(X) = op v0 (X). As all vertices belong to hypercubes with basis v 0 , the ladder set L v0,v for between v 0 and the only vertex v with ladder set L v0,v = X.
On general median graphs, the opposite label op u (L) allows us to obtain the maximum distance d(s, t) such that u = m(s, t, v 0 ) and the ladder set L u,s is L.
▶ Lemma 4.9 (Relationship between medians and disjoint outgoing POFs [15]). Let L, L ′ be two POFs outgoing from a vertex u. Let s (resp. t) be a vertex such that u ∈ I(v 0 , s) (resp. u ∈ I(v 0 , t)) and L u,s = L (resp. L u,t = L ′ ). Then, u ∈ I(s, t) if and only if L ∩ L ′ = ∅. Therefore, given a single vertex s such that u ∈ I(v 0 , s) and L u,s = L, the maximum distance d(s, v) we can have with median m(s, v, v 0 ) = u is exactly d(u, s) + φ(u, op u (L)).
Going further, given a vertex u ∈ V , the maximum distance d(s, t) such that u = m(s, t, v 0 ) is the maximum value φ(u, L) + φ(u, op u (L)), where L is a POF outgoing from u.
An algorithm was initially proposed to compute all labels op u (L) consisting in a brute force bounded tree search [15]. Its execution time wasÕ(2 O(d log d) n), leading to the global same asymptotic running time (Lemma 4.1) for finding all eccentricities.
Fortunately, the quasilinear time algorithm determining the eccentricities on simplex graphs (Theorem 3.8, Section 3) offers us the opportunity to decrease the exponential term to a simple exponential function 2 d . For any u ∈ V , let G u = G [V u ] be the star graph of u, using a definition from [22]. Its vertex set V u is made up of the vertices belonging to a hypercube with basis u in G. Graph G u is the induced subgraph of G on vertex set V u (see Figure 8 for an example). Chepoi et al. [22] showed that graph G u is a gated/convex subgraph of G. Applying the algorithm of Theorem 3.8 on the simplex graph G u provides us with the opposite labels of u.

Anti-ladder labels
We terminate with anti-ladder labels ψ which play the converse role of ladder labels φ. While φ(u, L) is defined for POFs L outgoing from u, labels ψ(u, R) are defined for POFs R incoming into u, i.e. every Θ-class of the POF has an edge entering u. As any such pair (u, R) can be associated with a hypercube of anti-basis u and signature R (Lemma A.6), the total size of ψ-labelings is at most O(2 d n) too.
The notion of milestone intervenes in the definition of labels ψ. We consider two vertices u, v such that u ∈ I(v 0 , v). Milestones are defined recursively. Π(u, v)). Let L u,v be the ladder set of u, v and u + be the anti-basis of the hypercube with basis u and signature L u,v . If u + = v, then pair u, v admits two milestones:

▶ Definition 4.11 (Milestones
The milestones are the successive anti-bases of the hypercubes formed by the vertices and ladder sets traversed from u to v. Both vertices u and v are contained in Π(u, v). The first milestone is u, the second is the anti-basis u + of the hypercube with basis u and signature L u,v . The third one is the anti-basis u ++ of the hypercube with basis u + and signature L u + ,v , etc. All milestones are metrically between u and v: Π(u, v) ⊆ I(u, v). ▶ Definition 4.12 (Penultimate milestone π(u, v)). We say that the milestone in Π(u, v) different from v but the closest to it is called the penultimate milestone. We denote it by π(u, v). Furthermore, we denote by L u,v the anti-ladder set of u, v, i.e. the Θ-classes of the hypercube with basis π(u, v) and anti-basis v.
Let R be a POF incoming to some vertex u and u − be the basis of the hypercube with anti-basis u and signature R. Label ψ(u, R) intuitively represents the maximum distance of a shortest path arriving to vertex u from "direction" R. As for the computation of labels φ, there is an induction process to determine all ψ(u, R). As the base case, suppose that u − = v 0 . The largest distance d (u, v) we can obtain with a vertex v such that v 0 ∈ I(u, v) consists in considering the opposite op v0 (R) of R which is outgoing from v 0 . Hence, ψ(u, R) = |R| + φ(v 0 , op v0 (R)).
For the induction step, we distinguish two cases. In the first one, assume that m (u, v, v u}. A shortest (u, v)-path is the concatenation of the shortest (u, u − )-path of length |R| with a shortest (u − , v)-path, and u − ∈ I(v 0 , v). The largest distance d(u, v) we can have, as for the base case, is ψ(u, R) = |R| + φ(u − , op u − (R)).
In the second case, m ̸ = u − , an inductive formula allows us to obtain ψ(u, R). A consequence of Lemma 4.6 is that, for two consecutive milestones in Π(u, v), say u and u + w.l.o.g, then L u + ,v is L u,v -parallel. This observation, applied to the penultimate milestone, provides us with the following theorem.
▶ Lemma 4.14 (Inductive formula for labels ψ [15]). Let u, v ∈ V and u ∈ I(v 0 , v). Let L be a POF outgoing from v and w the anti-basis of hypercube (v, L). The following propositions are equivalent: (i) vertex v is the penultimate milestone of (u, w): π(u, w) = v, (ii) the milestones of (u, w) are the milestones of (u, v) with w: Set Π(m, u) admits at least three milestones: m, u − , and u. Let R − be the POF incoming to u − which is the ladder set (but also the signature) of (i) the milestone just before u − and (ii) u − . According to Lemma 4.14, vertex u − is the penultimate milestone of (m, u) if and only if R − ∪ {E j } is not a POF, for each E j ∈ R. For this reason, value ψ(u, R) can be expressed as: Our algorithm consists in taking the maximum value between the two cases. The number of pairs ((u, R), (u − , R − )) which satisfy the condition described in Equation (2) is at most 2 2d n: it is identical to the one presented for φ-labelings.

Better time complexity for all eccentricities
The computation of all labels φ(u, L), op u (L) and ψ(u, R) gives an algorithm which determines all eccentricities. Indeed, each eccentricity ecc(u) is a function of certain labels φ and ψ. Let v be a vertex in G such that ecc(u) = d (u, v). given by a label φ(u, L). Otherwise, if m ̸ = u, let u − be the penultimate milestone in Π(m, u) and R be the classes of the hypercube with basis u − and anti-basis u. The eccentricity of u is given by a label ψ(u, R). Conversely, each φ(u, L) and ψ(u, R) is the distance between u and another vertex by definition. Therefore, we have: In other words, the eccentricity of u is the maximum label φ or ψ centered at u. We can conclude with the main result of this subsection: the eccentricities of any median graph can be determined in linear time multiplied by a simple exponential function 2 O(d) of the dimension d.
S TA C S 2 0 2 2 ▶ Theorem 4.16 (All eccentricities inÕ(2 2d n)-time for median graphs). There is a combinatorial algorithm computing the list of all eccentricities of a median graph G in timeÕ(2 2d n).

Tackling the general case
Our new FPT algorithm for computing the list of eccentricities in a median graph has a runtime in 2 O(d) n, with d being the dimension (Theorem 4.16). This runtime stays subquadratic in n as long as d < α log n, for some constant α < 1. In what follows, we present a simple partitioning scheme for median graphs into convex subgraphs of dimension at most α log n, for an arbitrary value of α ≤ 1. By doing so, we obtain (in combination with Theorem 4.16) the first known subquadratic-time algorithm for computing all eccentricities in a median graph.
We start with a simple relation between the eccentricity function of a median graph and the respective eccentricity functions of any two complementary halfspaces.

▶ Lemma 4.17 (B.2). Let G be a median graph. For every
We will use this above Lemma 4.17 later in our proof in order to compute in linear time the list of eccentricities in a median graph being given the lists of eccentricities in any two complementary halfspaces.
Next, we give simple properties of Θ-classes, to be used in the analysis of our main algorithm in this section (see Lemma 4.21). Proof. Let G be an n-vertex median graph. We compute its Θ-classes E 1 , E 2 , . . . , E q , that takes linear time (Lemma 2.3). For some parameter D (to be fixed later in the proof), let us assume without loss of generality E 1 , E 2 , . . . , E p to be the subset of all Θ-classes of cardinality ≥ D, for some p ≤ q. Note that we have p ≤ |E| /D =Õ(n/D).
We reduce the problem of computing all eccentricities in G to the same problem on every connected component of G \ (E 1 ∪ E 2 ∪ . . . ∪ E p ). More formally, we construct a rooted binary tree T , whose leaves are labelled with convex subgraphs of G. Initially, T is reduced to a single node with label equal to G. Then, for i = 1 . . . p, we further refine this tree so that, at the end of any step i, its leaves are labelled with the connected components of G \ (E 1 ∪ E 2 ∪ . . . ∪ E i ). An example of T is shown in Figure 5 with D = 3 and two Θ-classes reaching this cardinality bound.
For that, we proceed as follows. We consider all leaves of T whose label H satisfies , and in particular that they form a partition of V (G). Therefore, each step takes linear time by reduction to computing the connected components in vertex-disjoint subgraphs of G. Overall, the total time for constructing the tree T is in O(pm) =Õ(n 2 /D). Figure 5 An example of tree T associated with a graph G for D = 3: here, p = 2.
Then, we compute the list of eccentricities for all the subgraphs labelling a node, by dynamic programming on T . In particular, doing so we compute the list of eccentricities for G because it is the label of the root. There are two cases: If H labels a leaf (base case) then, we claim that we have dim(H) ≤ ⌊log D⌋ + 1. Indeed, by   [22,Lemma 17] for a detailed description of this standard procedure). Overall (by proceeding the same way for H ′′ i as for H ′ i ) we can compute the list of eccentricities for H inÕ(|V (H)|) time. This is in totalÕ(n) time for the i-nodes (i.e., because they were leaves of T at step i, and therefore, they are vertex-disjoint), and so, in totalÕ(pn) =Õ(n 2 /D) time for all the internal nodes. The total runtime for our algorithm isÕ(n 2 /D +D log c n), and optimized for D = n The concept of orthogonality is sometimes described with different words in the literature depending on the context: incompatible, concurrent or crossing. We say that E i and E j are parallel if they are not orthogonal, that is We pursue with a property on orthogonal Θ-classes: if two edges of two orthogonal classes E i and E j are incident, they belong to a common square.
▶ Lemma A.3 (Squares [11,15]). Let xu ∈ E i and uy ∈ E j . If E i and E j are orthogonal, then there is a vertex v such that uyvx is a square.
Pairwise orthogonal families. We focus on the set of Θ-classes which are pairwise orthogonal.

▶ Definition A.4 (Pairwise Orthogonal Family). We say that a set of classes X ⊆ E is a Pairwise Orthogonal Family (POF for short) if for any pair
This notion is not completely new, since it implicitely appears in certain properties established on median graphs (for instance, the downward cube property in [13]). The empty set is considered as a POF. We denote by L the set of POFs of the median graph G. The notion of POF is strongly related to the induced hypercubes in median graphs. First, observe that all Θ-classes of a median graph form a POF if and only if the graph is a hypercube of dimension log n [31,32]. Secondly, the next lemma precises the relationship between POFs and hypercubes.
▶ Lemma A.5 (POFs adjacent to a vertex [15]). Let X be a POF, v ∈ V , and assume that for each E i ∈ X, there is an edge of E i adjacent to v. There exists a hypercube Q containing vertex v and all edges of X adjacent to v. Moreover, the Θ-classes of the edges of Q are the classes of X.
There is a natural bijection between the vertices of a median graph and the POFs. The next lemma exhibits this relationship.
The number of POFs in G is equal to the number n of vertices: n = |L|.

9:19
Illustration of the bijection between V and the set of POFs.
An example is given in Figure 6 with a small median graph of dimension d = 2. v 0 is the canonical basepoint and edges are colored according to their Θ-class. For example, v 1 v 3 ∈ E 1 . We associate with any POF X of G the vertex v X satisfying E − (v X ) = X with the v 0 -orientation. Obviously, the empty POF is associated with v 0 which has no incoming edges.
A straightforward consequence of this bijection is that parameter q, the number of Θclasses, is less than the number of vertices n. But it can be used less trivially to enumerate the POFs of a median graph in linear time [8,31]. Given a basepoint v 0 , we say that the basis (resp. anti-basis) of an induced hypercube Q is the single vertex v such that all edges of the hypercube adjacent to v are outgoing from (resp. incoming into) v. Said differently, the basis of Q is its closest-to-v 0 vertex and its anti-basis is its farthest-to-v 0 vertex. What Lemma A.6 states is also that we can associate with any POF X a hypercube Q X which contains exactly the classes X and admits v X as its anti-basis. This observation implies that the number of POFs is less than the number of hypercubes in G. Moreover, the hypercube Q X is the closest-to-v 0 hypercube formed with the classes in X. Figure 7a shows a vertex v with its incoming and outgoing edges with the v 0 -orientation. The dashed edges represent the hypercube with anti-basis v and POF E − (v).
The hypercube "induced" by the edges incoming into a vertex (its antibasis).
A POF signing at least two hypercubes Q and Q ′ is not maximal.

Number of hypercubes.
We remind a formula establishing a relationship between the number of POFs and the number of hypercubes in the literature. Let α(G) (resp. β(G)) be the number of hypercubes (resp. POFs) in G. Let β i (G) be the number of POFs of cardinality i ≤ d in G. According to [8,31], we have: S TA C S 2 0 2 2 9:20

All Eccentricities on Median Graphs in Subquadratic Time
Equation (4) produces a natural upper bound for the number of hypercubes.
Value α(G) consider all hypercubes, in particular those of dimension 0, i.e. vertices. From now on, the word "hypercube" refers to the hypercubes of dimension at least one.
Each hypercube in the median graph G can be defined with only its anti-basis v and the edges N of the hypercube that are adjacent and going into v according to the v 0 -orientation. These edges are a subset of N − (v): N ⊆ N − (v). Conversely, given a vertex v, each subset of N − (v) produces a hypercube which admits v as an anti-basis (this hypercube is a subhypercube of the one obtained with v and N − (v), Lemma A.6). Another possible bijection is to consider a hypercube as a pair composed of its anti-basis v and the Θ-classes E of the edges in N (its signature).
As a consequence, a simple graph search as BFS enables us to enumerate the hypercubes in G in time O(d2 d n).
▶ Lemma A.8 (Enumeration of hypercubes [15]). We can enumerate all triplets (v, u, E), where v is the anti-basis of a hypercube Q, u its basis, and E the signature of Q in time O(d2 d n). Moreover, the list obtained fulfils the following partial order: if d(v 0 , v) < d(v 0 , v ′ ), then any triplet (v, u, E) containing v appears before any triplet (v ′ , u ′ , E ′ ) containing v ′ .
The enumeration of hypercubes is thus executed in linear time for median graphs with constant dimension. In summary, given any median graph, one can compute the set of Θ-classes and their orthogonality relationship (for each E i , the set of Θ-classes orthogonal to E i ) in linear time, and the set of hypercubes with its basis, anti-basis and signature iñ O(2 d n).

B
Proofs of Section 4 ▶ Theorem B.1 (Computation of labels op). There is a combinatorial algorithm which determines all labels op u (L) inÕ(2 d n).
Proof. Let u ∈ V : we denote by N u the number of hypercubes of G with basis u. Convex subgraphs of median graphs are also median by considering the original definition of median graphs (Definition 2.1). Consequently, star graph G u is median and all its maximal hypercubes contain a common vertex u. From Theorem 3.2, G u is a simplex graph.   Any pair (u, L) of G, where L is a POF outgoing from u in G, can be associated to a unique hypercube with signature L and basis u. Thus, there is a natural bijection between (i) the POFs of G u (ii) the vertices of G u and (iii) the POFs L of G outgoing from u. Hence, |V u | = N u .