# Median graph

In graph theory, a division of mathematics, a **median graph** is an undirected graph in which every three vertices *a*, *b*, and *c* have a unique *median*: a vertex *m*(*a*,*b*,*c*) that belongs to shortest paths between each pair of *a*, *b*, and *c*.

The concept of median graphs has long been studied, for instance by Birkhoff & Kiss (1947) or (more explicitly) by Avann (1961), but the first paper to call them "median graphs" appears to be Nebeský (1971). As Chung, Graham, and Saks write, "median graphs arise naturally in the study of ordered sets and discrete distributive lattices, and have an extensive literature".^{[1]} In phylogenetics, the Buneman graph representing all maximum parsimony evolutionary trees is a median graph.^{[2]} Median graphs also arise in social choice theory: if a set of alternatives has the structure of a median graph, it is possible to derive in an unambiguous way a majority preference among them.^{[3]}

Additional surveys of median graphs are given by Klavžar & Mulder (1999), Bandelt & Chepoi (2008), and Knuth (2008).

## Contents

- 1 Examples
- 2 Equivalent definitions
- 3 Distributive lattices and median algebras
- 4 Convex sets and Helly families
- 5 2-satisfiability
- 6 Retracts of hypercubes
- 7 Triangle-free graphs and recognition algorithms
- 8 Evolutionary trees, Buneman graphs, and Helly split systems
- 9 Additional properties
- 10 Notes
- 11 References
- 12 External links

## Examples[edit]

Every tree is a median graph.^{[4]} To see this, observe that in a tree, the union of the three shortest paths between pairs of the three vertices *a*, *b*, and *c* is either itself a path, or a subtree formed by three paths meeting at a single central node with degree three. If the union of the three paths is itself a path, the median *m*(*a*,*b*,*c*) is equal to one of *a*, *b*, or *c*, whichever of these three vertices is between the other two in the path. If the subtree formed by the union of the three paths is not a path, the median of the three vertices is the central degree-three node of the subtree.

Additional examples of median graphs are provided by the grid graphs. In a grid graph, the coordinates of the median *m*(*a*,*b*,*c*) can be found as the median of the coordinates of *a*, *b*, and *c*. Conversely, it turns out that, in every median graph, one may label the vertices by points in an integer lattice in such a way that medians can be calculated coordinatewise in this way.^{[5]}

Squaregraphs, planar graphs in which all interior faces are quadrilaterals and all interior vertices have four or more incident edges, are another subclass of the median graphs.^{[6]} A polyomino is a special case of a squaregraph and therefore also forms a median graph.^{[7]}

The simplex graph κ(*G*) of an arbitrary undirected graph *G* has a vertex for every clique (complete subgraph) of *G*; two vertex of κ(*G*) are linked by an edge if the corresponding cliques differ by one vertex of *G* . The simplex graph is always a median graph, in which the median of a given triple of cliques may be formed by using the majority rule to determine which vertices of the cliques to include.^{[8]}

No cycle graph of length other than four can be a median graph. Every such cycle has three vertices *a*, *b*, and *c* such that the three shortest paths wrap all the way around the cycle without having a common intersection. For such a triple of vertices, there can be no median.

## Equivalent definitions[edit]

In an arbitrary graph, for each two vertices *a* and *b*, the minimal number of edges between them is called their *distance*, denoted by *d*(*x*,*y*). The *interval* of vertices that lie on shortest paths between *a* and *b* is defined as

*I*(*a*,*b*) = {*v*|*d*(*a*,*b*) =*d(a,v)*+*d(v,b)*}.

A median graph is defined by the property that, for every three vertices *a*, *b*, and *c*, these intervals intersect in a single point:

- For all
*a*,*b*, and*c*, |*I*(*a*,*b*) ∩*I*(*a*,*c*) ∩*I*(*b*,*c*)| = 1.

Equivalently, for every three vertices *a*, *b*, and *c* one can find a vertex *m*(*a*,*b*,*c*) such that the unweighted distances in the graph satisfy the equalities

*d*(*a*,*b*) =*d*(*a*,*m*(*a*,*b*,*c*)) +*d*(*m*(*a*,*b*,*c*),*b*)*d*(*a*,*c*) =*d*(*a*,*m*(*a*,*b*,*c*)) +*d*(*m*(*a*,*b*,*c*),*c*)*d*(*b*,*c*) =*d*(*b*,*m*(*a*,*b*,*c*)) +*d*(*m*(*a*,*b*,*c*),*c*)

and *m*(*a*,*b*,*c*) is the only vertex for which this is true.

It is also possible to define median graphs as the solution sets of 2-satisfiability problems, as the retracts of hypercubes, as the graphs of finite median algebras, as the Buneman graphs of Helly split systems, and as the graphs of windex 2; see the sections below.

## Distributive lattices and median algebras[edit]

In lattice theory, the graph of a finite lattice has a vertex for each lattice element and an edge for each pair of elements in the covering relation of the lattice. Lattices are commonly presented visually via Hasse diagrams, which are drawings of graphs of lattices. These graphs, especially in the case of distributive lattices, turn out to be closely related to median graphs.

In a distributive lattice, Birkhoff's self-dual ternary median operation^{[9]}

*m*(*a*,*b*,*c*) = (*a*∧*b*) ∨ (*a*∧*c*) ∨ (*b*∧*c*) = (*a*∨*b*) ∧ (*a*∨*c*) ∧ (*b*∨*c*),

satisfies certain key axioms, which it shares with the usual median of numbers in the range from 0 to 1 and with median algebras more generally:

- Idempotence:
*m(a,a,b)*=*a*for all*a*and*b*. - Commutativity:
*m*(*a*,*b*,*c*) =*m(a,c,b)*=*m(b,a,c)*=*m(b,c,a)*=*m(c,a,b)*=*m(c,b,a)*for all*a*,*b*, and*c*. - Distributivity:
*m(a,m(b,c,d),e)*=*m(m(a,b,e),c,m(a,d,e))*for all*a*,*b*,*c*,*d*, and*e*. - Identity elements:
*m*(0,*a*,1) =*a*for all*a*.

The distributive law may be replaced by an associative law:^{[10]}

- Associativity:
*m*(*x*,*w*,*m*(*y*,*w*,*z*)) =*m*(*m*(*x*,*w*,*y*),*w*,*z*)

The median operation may also be used to define a notion of intervals for distributive lattices:

*I*(*a*,*b*) = {*x*|*m(a,x,b)*=*x*} = {*x*|*a*∧*b*≤*x*≤*a*∨*b*}.^{[11]}

The graph of a finite distributive lattice has an edge between vertices *a* and *b* whenever *I*(*a*,*b*) = {*a*,*b*}. For every two vertices *a* and *b* of this graph, the interval *I*(*a*,*b*) defined in lattice-theoretic terms above consists of the vertices on shortest paths from *a* to *b*, and thus coincides with the graph-theoretic intervals defined earlier. For every three lattice elements *a*, *b*, and *c*, *m*(*a*,*b*,*c*) is the unique intersection of the three intervals *I*(*a*,*b*), *I*(*a*,*c*), and *I*(*b*,*c*).^{[12]} Therefore, the graph of an arbitrary finite distributive lattice is a median graph. Conversely, if a median graph *G* contains two vertices 0 and 1 such that every other vertex lies on a shortest path between the two (equivalently, *m*(0,*a*,1) = *a* for all *a*), then we may define a distributive lattice in which *a* ∧ *b* = *m*(*a*,0,*b*) and *a* ∨ *b* = *m*(*a*,1,*b*), and *G* will be the graph of this lattice.^{[13]}

Duffus & Rival (1983) characterize graphs of distributive lattices directly as diameter-preserving retracts of hypercubes. More generally, every median graph gives rise to a ternary operation *m* satisfying idempotence, commutativity, and distributivity, but possibly without the identity elements of a distributive lattice. Every ternary operation on a finite set that satisfies these three properties (but that does not necessarily have 0 and 1 elements) gives rise in the same way to a median graph.^{[14]}

## Convex sets and Helly families[edit]

In a median graph, a set *S* of vertices is said to be convex if, for every two vertices *a* and *b* belonging to *S*, the whole interval *I*(*a*,*b*) is a subset of *S*. Equivalently, given the two definitions of intervals above, *S* is convex if it contains every shortest path between two of its vertices, or if it contains the median of every set of three points at least two of which are from *S*. Observe that the intersection of every pair of convex sets is itself convex.^{[15]}

The convex sets in a median graph have the Helly property: if *F* is an arbitrary family of pairwise-intersecting convex sets, then all sets in *F* have a common intersection.^{[16]} For, if *F* has only three convex sets *S*, *T*, and *U* in it, with *a* in the intersection of the pair *S* and *T*, *b* in the intersection of the pair *T* and *U*, and *c* in the intersection of the pair *S* and *U*, then every shortest path from *a* to *b* must lie within *T* by convexity, and similarly every shortest path between the other two pairs of vertices must lie within the other two sets; but *m*(*a*,*b*,*c*) belongs to paths between all three pairs of vertices, so it lies within all three sets, and forms part of their common intersection. If *F* has more than three convex sets in it, the result follows by induction on the number of sets, for one may replace an arbitrary pair of sets in *F* by their intersection, using the result for triples of sets to show that the replaced family is still pairwise intersecting.

A particularly important family of convex sets in a median graph, playing a role similar to that of halfspaces in Euclidean space, are the sets

*W*= {_{uv}*w*|*d*(*w*,*u*) <*d*(*w*,*v*)}

defined for each edge *uv* of the graph. In words, *W _{uv}* consists of the vertices closer to

*u*than to

*v*, or equivalently the vertices

*w*such that some shortest path from

*v*to

*w*goes through

*u*. To show that

*W*is convex, let

_{uv}*w*

_{1}

*w*

_{2}...

*w*

_{k}be an arbitrary shortest path that starts and ends within

*W*; then

_{uv}*w*

_{2}must also lie within

*W*, for otherwise the two points

_{uv}*m*

_{1}=

*m*(

*u*,

*w*

_{1},

*w*

_{k}) and

*m*

_{2}=

*m*(

*m*

_{1},

*w*

_{2}...

*w*

_{k}) could be shown (by considering the possible distances between the vertices) to be distinct medians of

*u*,

*w*

_{1}, and

*w*

_{k}, contradicting the definition of a median graph which requires medians to be unique. Thus, each successive vertex on a shortest path between two vertices of

*W*also lies within

_{uv}*W*, so

_{uv}*W*contains all shortest paths between its nodes, one of the definitions of convexity.

_{uv}The Helly property for the sets *W _{uv}* plays a key role in the characterization of median graphs as the solution of 2-satisfiability instances, below.

## 2-satisfiability[edit]

Median graphs have a close connection to the solution sets of 2-satisfiability problems that can be used both to characterize these graphs and to relate them to adjacency-preserving maps of hypercubes.^{[17]}

A 2-satisfiability instance consists of a collection of Boolean variables and a collection of *clauses*, constraints on certain pairs of variables requiring those two variables to avoid certain combinations of values. Usually such problems are expressed in conjunctive normal form, in which each clause is expressed as a disjunction and the whole set of constraints is expressed as a conjunction of clauses, such as

A solution to such an instance is an assignment of truth values to the variables that satisfies all the clauses, or equivalently that causes the conjunctive normal form expression for the instance to become true when the variable values are substituted into it. The family of all solutions has a natural structure as a median algebra, where the median of three solutions is formed by choosing each truth value to be the majority function of the values in the three solutions; it is straightforward to verify that this median solution cannot violate any of the clauses. Thus, these solutions form a median graph, in which the neighbor of each solution is formed by negating a set of variables that are all constrained to be equal or unequal to each other.

Conversely, every median graph *G* may be represented in this way as the solution set to a 2-satisfiability instance. To find such a representation, create a 2-satisfiability instance in which each variable describes the orientation of one of the edges in the graph (an assignment of a direction to the edge causing the graph to become directed rather than undirected) and each constraint allows two edges to share a pair of orientations only when there exists a vertex *v* such that both orientations lie along shortest paths from other vertices to *v*. Each vertex *v* of *G* corresponds to a solution to this 2-satisfiability instance in which all edges are directed towards *v*. Each solution to the instance must come from some vertex *v* in this way, where *v* is the common intersection of the sets *W _{uw}* for edges directed from

*w*to

*u*; this common intersection exists due to the Helly property of the sets

*W*. Therefore, the solutions to this 2-satisfiability instance correspond one-for-one with the vertices of

_{uw}*G*.

## Retracts of hypercubes[edit]

A *retraction* of a graph *G* is an adjacency-preserving map from *G* to one of its subgraphs.^{[18]} More precisely, it is graph homomorphism φ from *G* to itself such that φ(*v*) = *v* for each vertex *v* in the subgraph φ(G). The image of the retraction is called a *retract* of *G*. Retractions are examples of metric maps: the distance between φ(*v*) and φ(*w*), for every *v* and *w*, is at most equal to the distance between *v* and *w*, and is equal whenever *v* and *w* both belong to φ(*G*). Therefore, a retract must be an *isometric subgraph* of *G*: distances in the retract equal those in *G*.

If *G* is a median graph, and *a*, *b*, and *c* are an arbitrary three vertices of a retract φ(*G*), then φ(*m*(*a*,*b*,*c*)) must be a median of *a*, *b*, and *c*, and so must equal *m*(*a*,*b*,*c*). Therefore, φ(*G*) contains medians of all triples of its vertices, and must also be a median graph. In other words, the family of median graphs is closed under the retraction operation.^{[19]}

A hypercube graph, in which the vertices correspond to all possible *k*-bit bitvectors and in which two vertices are adjacent when the corresponding bitvectors differ in only a single bit, is a special case of a *k*-dimensional grid graph and is therefore a median graph. The median of three bitvectors *a*, *b*, and *c* may be calculated by computing, in each bit position, the majority function of the bits of *a*, *b*, and *c*. Since median graphs are closed under retraction, and include the hypercubes, every retract of a hypercube is a median graph.

Conversely, every median graph must be the retract of a hypercube.^{[20]} This may be seen from the connection, described above, between median graphs and 2-satisfiability: let *G* be the graph of solutions to a 2-satisfiability instance; without loss of generality this instance can be formulated in such a way that no two variables are always equal or always unequal in every solution. Then the space of all truth assignments to the variables of this instance forms a hypercube. For each clause, formed as the disjunction of two variables or their complements, in the 2-satisfiability instance, one can form a retraction of the hypercube in which truth assignments violating this clause are mapped to truth assignments in which both variables satisfy the clause, without changing the other variables in the truth assignment. The composition of the retractions formed in this way for each of the clauses gives a retraction of the hypercube onto the solution space of the instance, and therefore gives a representation of *G* as the retract of a hypercube. In particular, median graphs are isometric subgraphs of hypercubes, and are therefore partial cubes. However, not all partial cubes are median graphs; for instance, a six-vertex cycle graph is a partial cube but is not a median graph.

As Imrich & Klavžar (2000) describe, an isometric embedding of a median graph into a hypercube may be constructed in time O(*m* log *n*), where *n* and *m* are the numbers of vertices and edges of the graph respectively.^{[21]}

## Triangle-free graphs and recognition algorithms[edit]

The problems of testing whether a graph is a median graph, and whether a graph is triangle-free, both had been well studied when Imrich, Klavžar & Mulder (1999) observed that, in some sense, they are computationally equivalent.^{[22]} Therefore, the best known time bound for testing whether a graph is triangle-free, O(*m*^{1.41}),^{[23]} applies as well to testing whether a graph is a median graph, and any improvement in median graph testing algorithms would also lead to an improvement in algorithms for detecting triangles in graphs.

In one direction, suppose one is given as input a graph *G*, and must test whether *G* is triangle-free. From *G*, construct a new graph *H* having as vertices each set of zero, one, or two adjacent vertices of *G*. Two such sets are adjacent in *H* when they differ by exactly one vertex. An equivalent description of *H* is that it is formed by splitting each edge of *G* into a path of two edges, and adding a new vertex connected to all the original vertices of *G*. This graph *H* is by construction a partial cube, but it is a median graph only when *G* is triangle-free: if *a*, *b*, and *c* form a triangle in *G*, then {*a*,*b*}, {*a*,*c*}, and {*b*,*c*} have no median in *H*, for such a median would have to correspond to the set {*a*,*b*,*c*}, but sets of three or more vertices of *G* do not form vertices in *H*. Therefore, *G* is triangle-free if and only if *H* is a median graph. In the case that *G* is triangle-free, *H* is its simplex graph. An algorithm to test efficiently whether *H* is a median graph could by this construction also be used to test whether *G* is triangle-free. This transformation preserves the computational complexity of the problem, for the size of *H* is proportional to that of *G*.

The reduction in the other direction, from triangle detection to median graph testing, is more involved and depends on the previous median graph recognition algorithm of Hagauer, Imrich & Klavžar (1999), which tests several necessary conditions for median graphs in near-linear time. The key new step involves using a breadth first search to partition the graph's vertices into levels according to their distances from some arbitrarily chosen root vertex, forming a graph from each level in which two vertices are adjacent if they share a common neighbor in the previous level, and searching for triangles in these graphs. The median of any such triangle must be a common neighbor of the three triangle vertices; if this common neighbor does not exist, the graph is not a median graph. If all triangles found in this way have medians, and the previous algorithm finds that the graph satisfies all the other conditions for being a median graph, then it must actually be a median graph. This algorithm requires, not just the ability to test whether a triangle exists, but a list of all triangles in the level graph. In arbitrary graphs, listing all triangles sometimes requires Ω(*m*^{3/2}) time, as some graphs have that many triangles, however Hagauer et al. show that the number of triangles arising in the level graphs of their reduction is near-linear, allowing the Alon et al. fast matrix multiplication based technique for finding triangles to be used.

## Evolutionary trees, Buneman graphs, and Helly split systems[edit]

Phylogeny is the inference of evolutionary trees from observed characteristics of species; such a tree must place the species at distinct vertices, and may have additional *latent vertices*, but the latent vertices are required to have three or more incident edges and must also be labeled with characteristics. A characteristic is *binary* when it has only two possible values, and a set of species and their characteristics exhibit perfect phylogeny when there exists an evolutionary tree in which the vertices (species and latent vertices) labeled with any particular characteristic value form a contiguous subtree. If a tree with perfect phylogeny is not possible, it is often desired to find one exhibiting maximum parsimony, or equivalently, minimizing the number of times the endpoints of a tree edge have different values for one of the characteristics, summed over all edges and all characteristics.

Buneman (1971) described a method for inferring perfect phylogenies for binary characteristics, when they exist. His method generalizes naturally to the construction of a median graph for any set of species and binary characteristics, which has been called the *median network* or *Buneman graph*^{[24]} and is a type of phylogenetic network. Every maximum parsimony evolutionary tree embeds into the Buneman graph, in the sense that tree edges follow paths in the graph and the number of characteristic value changes on the tree edge is the same as the number in the corresponding path. The Buneman graph will be a tree if and only if a perfect phylogeny exists; this happens when there are no two incompatible characteristics for which all four combinations of characteristic values are observed.

To form the Buneman graph for a set of species and characteristics, first, eliminate redundant species that are indistinguishable from some other species and redundant characteristics that are always the same as some other characteristic. Then, form a latent vertex for every combination of characteristic values such that every two of the values exist in some known species. In the example shown, there are small brown tailless mice, small silver tailless mice, small brown tailed mice, large brown tailed mice, and large silver tailed mice; the Buneman graph method would form a latent vertex corresponding to an unknown species of small silver tailed mice, because every pairwise combination (small and silver, small and tailed, and silver and tailed) is observed in some other known species. However, the method would not infer the existence of large brown tailless mice, because no mice are known to have both the large and tailless traits. Once the latent vertices are determined, form an edge between every pair of species or latent vertices that differ in a single characteristic.

One can equivalently describe a collection of binary characteristics as a *split system*, a family of sets having the property that the complement set of each set in the family is also in the family. This split system has a set for each characteristic value, consisting of the species that have that value. When the latent vertices are included, the resulting split system has the Helly property: every pairwise intersecting subfamily has a common intersection. In some sense median graphs are characterized as coming from Helly split systems: the pairs (*W _{uv}*,

*W*) defined for each edge

_{vu}*uv*of a median graph form a Helly split system, so if one applies the Buneman graph construction to this system no latent vertices will be needed and the result will be the same as the starting graph.

^{[25]}

Bandelt et al. (1995) and Bandelt, Macaulay & Richards (2000) describe techniques for simplified hand calculation of the Buneman graph, and use this construction to visualize human genetic relationships.

## Additional properties[edit]

- The Cartesian product of every two median graphs is another median graph. Medians in the product graph may be computed by independently finding the medians in the two factors, just as medians in grid graphs may be computed by independently finding the median in each linear dimension.
- The
*windex*of a graph measures the amount of lookahead needed to optimally solve a problem in which one is given a sequence of graph vertices*s*, and must find as output another sequence of vertices_{i}*t*minimizing the sum of the distances_{i}*d(s*and_{i},t_{i})*d(t*_{i − 1},*t*. Median graphs are exactly the graphs that have_{i})*windex*2. In a median graph, the optimal choice is to set*t*=_{i}*m*(*t*_{i − 1},*s*,_{i}*s*_{i + 1}).^{[1]} - The property of having a unique median is also called the
*unique Steiner point property*.^{[1]}An optimal Steiner tree for three vertices*a*,*b*, and*c*in a median graph may be found as the union of three shortest paths, from*a*,*b*, and*c*to*m*(*a*,*b*,*c*). Bandelt & Barthélémy (1984) study more generally the problem of finding the vertex minimizing the sum of distances to each of a given set of vertices, and show that it has a unique solution for any odd number of vertices in a median graph. They also show that this median of a set*S*of vertices in a median graph satisfies the Condorcet criterion for the winner of an election: compared to any other vertex, it is closer to a majority of the vertices in*S*. - As with partial cubes more generally, every median graph with
*n*vertices has at most (*n*/2) log_{2}*n*edges. However, the number of edges cannot be too small: Klavžar, Mulder & Škrekovski (1998) prove that in every median graph the inequality 2*n*−*m*−*k*≤ 2 holds, where*m*is the number of edges and*k*is the dimension of the hypercube that the graph is a retract of. This inequality is an equality if and only if the median graph contains no cubes. This is a consequence of another identity for median graphs: the Euler characteristic Σ (-1)^{dim(Q)}is always equal to one, where the sum is taken over all hypercube subgraphs*Q*of the given median graph.^{[26]} - The only regular median graphs are the hypercubes.
^{[27]} - Every median graph is a modular graph. The modular graphs are a class of graphs in which every triple of vertices has a median but the medians are not required to be unique.
^{[28]}

## Notes[edit]

- ^
^{a}^{b}^{c}Chung, Graham & Saks (1987). **^**Buneman (1971); Dress et al. (1997); Dress, Huber & Moulton (1997).**^**Bandelt & Barthélémy (1984); Day & McMorris (2003).**^**Imrich & Klavžar (2000), Proposition 1.26, p. 24.**^**This follows immediately from the characterization of median graphs as retracts of hypercubes, described below.**^**Soltan, Zambitskii & Prisăcaru (1973); Chepoi, Dragan & Vaxès (2002); Chepoi, Fanciullini & Vaxès (2004).**^**Klavžar & Škrekovski (2000).**^**Barthélemy, Leclerc & Monjardet (1986), page 200.**^**Birkhoff & Kiss (1947) credit the definition of this operation to Birkhoff, G. (1940),*Lattice Theory*, American Mathematical Society, p. 74.**^**Knuth (2008), p. 65, and exercises 75 and 76 on pp. 89–90. Knuth states that a simple proof that associativity implies distributivity remains unknown.**^**The equivalence between the two expressions in this equation, one in terms of the median operation and the other in terms of lattice operations and inequalities is Theorem 1 of Birkhoff & Kiss (1947).**^**Birkhoff & Kiss (1947), Theorem 2.**^**Birkhoff & Kiss (1947), p. 751.**^**Avann (1961).**^**Knuth (2008) calls such a set an*ideal*, but a convex set in the graph of a distributive lattice is not the same thing as an ideal of the lattice.**^**Imrich & Klavžar (2000), Theorem 2.40, p. 77.**^**Bandelt & Chepoi (2008), Proposition 2.5, p.8; Chung, Graham & Saks (1989); Feder (1995); Knuth (2008), Theorem S, p. 72.**^**Hell (1976).**^**Imrich & Klavžar (2000), Proposition 1.33, p. 27.**^**Bandelt (1984); Imrich & Klavžar (2000), Theorem 2.39, p.76; Knuth (2008), p. 74.**^**The technique, which culminates in Lemma 7.10 on p.218 of Imrich and Klavžar, consists of applying an algorithm of Chiba & Nishizeki (1985) to list all 4-cycles in the graph*G*, forming an undirected graph having as its vertices the edges of*G*and having as its edges the opposite sides of a 4-cycle, and using the connected components of this derived graph to form hypercube coordinates. An equivalent algorithm is Knuth (2008), Algorithm H, p. 69.**^**For previous median graph recognition algorithms, see Jha & Slutzki (1992), Imrich & Klavžar (1998), and Hagauer, Imrich & Klavžar (1999). For triangle detection algorithms, see Itai & Rodeh (1978), Chiba & Nishizeki (1985), and Alon, Yuster & Zwick (1995).**^**Alon, Yuster & Zwick (1995), based on fast matrix multiplication. Here*m*is the number of edges in the graph, and the big O notation hides a large constant factor; the best practical algorithms for triangle detection take time O(*m*^{3/2}). For median graph recognition, the time bound can be expressed either in terms of*m*or*n*(the number of vertices), as*m*= O(*n*log*n*).**^**Mulder & Schrijver (1979) described a version of this method for systems of characteristics not requiring any latent vertices, and Barthélémy (1989) gives the full construction. The Buneman graph name is given in Dress et al. (1997) and Dress, Huber & Moulton (1997).**^**Mulder & Schrijver (1979).**^**Škrekovski (2001).**^**Mulder (1980).**^**Modular graphs, Information System on Graph Classes and their Inclusions, retrieved 2016-09-30.

## References[edit]

- Alon, Noga; Yuster, Raphael; Zwick, Uri (1995), "Color-coding",
*Journal of the ACM*,**42**(4): 844–856, doi:10.1145/210332.210337, MR 1411787. - Avann, S. P. (1961), "Metric ternary distributive semi-lattices",
*Proceedings of the American Mathematical Society*, American Mathematical Society,**12**(3): 407–414, doi:10.2307/2034206, JSTOR 2034206, MR 0125807. - Bandelt, Hans-Jürgen (1984), "Retracts of hypercubes",
*Journal of Graph Theory*,**8**(4): 501–510, doi:10.1002/jgt.3190080407, MR 0766499. - Bandelt, Hans-Jürgen; Barthélémy, Jean-Pierre (1984), "Medians in median graphs",
*Discrete Applied Mathematics*,**8**(2): 131–142, doi:10.1016/0166-218X(84)90096-9, MR 0743019. - Bandelt, Hans-Jürgen; Chepoi, Victor (2008), "Metric graph theory and geometry: a survey" (PDF),
*Surveys on Discrete and Computational Geometry*, Contemporary Mathematics,**453**, Providence, RI: American Mathematical Society, pp. 49–86, doi:10.1090/conm/453/08795, MR 2405677. - Bandelt, Hans-Jürgen; Forster, P.; Sykes, B. C.; Richards, Martin B. (October 1, 1995), "Mitochondrial portraits of human populations using median networks",
*Genetics*,**141**(2): 743–753, PMC 1206770 , PMID 8647407. - Bandelt, Hans-Jürgen; Forster, P.; Rohl, Arne (January 1, 1999), "Median-joining networks for inferring intraspecific phylogenies",
*Molecular Biology and Evolution*,**16**(1): 37–48, doi:10.1093/oxfordjournals.molbev.a026036, PMID 10331250. - Bandelt, Hans-Jürgen; Macaulay, Vincent; Richards, Martin B. (2000), "Median networks: speedy construction and greedy reduction, one simulation, and two case studies from human mtDNA",
*Molecular Phylogenetics and Evolution*,**16**(1): 8–28, doi:10.1006/mpev.2000.0792, PMID 10877936. - Barthélémy, Jean-Pierre (1989), "From copair hypergraphs to median graphs with latent vertices",
*Discrete Mathematics*,**76**(1): 9–28, doi:10.1016/0012-365X(89)90283-5, MR 1002234. - Barthélemy, J.-P.; Leclerc, B.; Monjardet, B. (1986), "On the use of ordered sets in problems of comparison and consensus of classifications",
*Journal of Classification*,**3**(2): 187–224, doi:10.1007/BF01894188. - Birkhoff, Garrett; Kiss, S. A. (1947), "A ternary operation in distributive lattices",
*Bulletin of the American Mathematical Society*,**53**(1): 749–752, doi:10.1090/S0002-9904-1947-08864-9, MR 0021540. - Buneman, P. (1971), "The recovery of trees from measures of dissimilarity", in Hodson, F. R.; Kendall, D. G.; Tautu, P. T.,
*Mathematics in the Archaeological and Historical Sciences*, Edinburgh University Press, pp. 387–395. - Chepoi, V.; Dragan, F.; Vaxès, Y. (2002), "Center and diameter problems in planar quadrangulations and triangulations",
*Proc. 13th ACM-SIAM Symposium on Discrete Algorithms*, pp. 346–355. - Chepoi, V.; Fanciullini, C.; Vaxès, Y. (2004), "Median problem in some plane triangulations and quadrangulations",
*Computational Geometry: Theory & Applications*,**27**: 193–210, doi:10.1016/j.comgeo.2003.11.002. - Chiba, N.; Nishizeki, T. (1985), "Arboricity and subgraph listing algorithms",
*SIAM Journal on Computing*,**14**: 210–223, doi:10.1137/0214017, MR 0774940. - Chung, F. R. K.; Graham, R. L.; Saks, M. E. (1987), "Dynamic search in graphs", in Wilf, H.,
*Discrete Algorithms and Complexity (Kyoto, 1986)*(PDF), Perspectives in Computing,**15**, New York: Academic Press, pp. 351–387, MR 0910939. - Chung, F. R. K.; Graham, R. L.; Saks, M. E. (1989), "A dynamic location problem for graphs" (PDF),
*Combinatorica*,**9**(2): 111–132, doi:10.1007/BF02124674. - Day, William H. E.; McMorris, F. R. (2003),
*Axiomatic Consensus Theory in Group Choice and Bioinformatics*, Society for Industrial and Applied Mathematics, pp. 91–94, ISBN 0-89871-551-2. - Dress, A.; Hendy, M.; Huber, K.; Moulton, V. (1997), "On the number of vertices and edges of the Buneman graph",
*Annals of Combinatorics*,**1**(1): 329–337, doi:10.1007/BF02558484, MR 1630739. - Dress, A.; Huber, K.; Moulton, V. (1997), "Some variations on a theme by Buneman",
*Annals of Combinatorics*,**1**(1): 339–352, doi:10.1007/BF02558485, MR 1630743. - Duffus, Dwight; Rival, Ivan (1983), "Graphs orientable as distributive lattices",
*Proceedings of the American Mathematical Society*, American Mathematical Society,**88**(2): 197–200, doi:10.2307/2044697, JSTOR 2044697. - Feder, T. (1995),
*Stable Networks and Product Graphs*, Memoirs of the American Mathematical Society,**555**. - Hagauer, Johann; Imrich, Wilfried; Klavžar, Sandi (1999), "Recognizing median graphs in subquadratic time",
*Theoretical Computer Science*,**215**(1–2): 123–136, doi:10.1016/S0304-3975(97)00136-9, MR 1678773. - Hell, Pavol (1976), "Graph retractions",
*Colloquio Internazionale sulle Teorie Combinatorie (Roma, 1973), Tomo II*, Atti dei Convegni Lincei,**17**, Rome: Accad. Naz. Lincei, pp. 263–268, MR 0543779. - Imrich, Wilfried; Klavžar, Sandi (1998), "A convexity lemma and expansion procedures for bipartite graphs",
*European Journal of Combinatorics*,**19**(6): 677–686, doi:10.1006/eujc.1998.0229, MR 1642702. - Imrich, Wilfried; Klavžar, Sandi (2000),
*Product Graphs: Structure and Recognition*, Wiley, ISBN 0-471-37039-8, MR 0788124. - Imrich, Wilfried; Klavžar, Sandi; Mulder, Henry Martyn (1999), "Median graphs and triangle-free graphs",
*SIAM Journal on Discrete Mathematics*,**12**(1): 111–118, doi:10.1137/S0895480197323494, MR 1666073. - Itai, A.; Rodeh, M. (1978), "Finding a minimum circuit in a graph",
*SIAM Journal on Computing*,**7**(4): 413–423, doi:10.1137/0207033, MR 0508603. - Jha, Pranava K.; Slutzki, Giora (1992), "Convex-expansion algorithms for recognizing and isometric embedding of median graphs",
*Ars Combinatoria*,**34**: 75–92, MR 1206551. - Klavžar, Sandi; Mulder, Henry Martyn (1999), "Median graphs: characterizations, location theory and related structures",
*Journal of Combinatorial Mathematics and Combinatorial Computing*,**30**: 103–127, MR 1705337. - Klavžar, Sandi; Mulder, Henry Martyn; Škrekovski, Riste (1998), "An Euler-type formula for median graphs",
*Discrete Mathematics*,**187**(1): 255–258, doi:10.1016/S0012-365X(98)00019-3, MR 1630736. - Klavžar, Sandi; Škrekovski, Riste (2000), "On median graphs and median grid graphs",
*Discrete Mathematics*,**219**(1-3): 287–293, doi:10.1016/S0012-365X(00)00085-6, MR 1761732. - Knuth, Donald E. (2008), "Median algebras and median graphs",
*The Art of Computer Programming*, IV, Fascicle 0: Introduction to Combinatorial Algorithms and Boolean Functions, Addison-Wesley, pp. 64–74, ISBN 978-0-321-53496-5. - Mulder, Henry Martyn (1980), "n-cubes and median graphs",
*Journal of Graph Theory*,**4**(1): 107–110, doi:10.1002/jgt.3190040112, MR 0558458. - Mulder, Henry Martyn; Schrijver, Alexander (1979), "Median graphs and Helly hypergraphs",
*Discrete Mathematics*,**25**(1): 41–50, doi:10.1016/0012-365X(79)90151-1, MR 0522746. - Nebeský, Ladislav (1971), "Median graphs",
*Commentationes Mathematicae Universitatis Carolinae*,**12**: 317–325, MR 0286705. - Škrekovski, Riste (2001), "Two relations for median graphs",
*Discrete Mathematics*,**226**(1): 351–353, doi:10.1016/S0012-365X(00)00120-5, MR 1802603. - Soltan, P.; Zambitskii, D.; Prisăcaru, C. (1973),
*Extremal problems on graphs and algorithms of their solution*(in Russian), Chişinău: Ştiinţa.

## External links[edit]

- Median graphs, Information System for Graph Class Inclusions.
- Network, Free Phylogenetic Network Software. Network generates evolutionary trees and networks from genetic, linguistic, and other data.
- PhyloMurka, open-source software for median network computations from biological data.