The distance matrix of a graph and its tree realization
The results of Hakimi and Yau and others in the realization of a distance matrix are generalized to graphs (digraphs) whose branches (arcs) may have negative weights. Conditions under which such matrices have a tree, hypertree or directed tree realization are given, uniqueness of these realizations is discussed and algorithms for their construction are indicated. 1. Notation. A number of definitions are given so that results will be presented in a self-contained manner. A graph G = (V, B) consists of a finite non-empty set V = ••• , vn\ of vertices and a set 5 = {bt ,b2, • ■ ■ ,bm} of unordered pairs of distinct vertices of V. Each such pair bk = e(i\ , v,) of vertices is a branch of G and is said to be incident at both v{ and y,. A directed graph or digraph G = (F, A) consists of a finite non-empty set V = {f'i , v2 , • • • , vn] of vertices and a set A = {al , a2 , ■ ■ ■ , am] of ordered pairs of distinct vertices of V. Each such pair ak — e(v< , v,) of vertices is an arc of G, is directed from v{ to v, and is incident at both v, and v, . A subgraph of a graph (digraph) G is a graph (digraph) which has all its vertices and branches (arcs) in G. The degree of a vertex Vi in G, denoted deg (y, , G), is the number of branches (arcs) incident at i>, in G. The outdegree of a vertex v{ in digraph G, denoted outdeg(y, , G), is equal to the number of arcs incident at v, in G and directed away from v{. The indegree of Vi, denoted indeg(z\-, G), is equal to the number of arcs incident at v{ in G and directed towards v{ . A weighted graph (digraph) is a graph (digraph) together with a function which assigns a real number wx to each branch h, (arc a,). All graphs (digraphs) presented here are weighted. An edge-sequence in a graph (digraph) between two vertices v, and vf is an alternating sequence of vertices and branches (arcs) • • • M,beginning and ending with Vi and Vj , in which each branch (arc) is incident at the vertex preceding and the vertex following it. A path from to v,is the set of all branches (arcs) in an edge-sequence between v{ and v, . A directed path in a digraph is a path in which each arc is directed from the vertex preceding it to the vertex following it in the corresponding edge-sequence. A path or directed path is called elementary if all vertices in the edge-sequence are distinct. A path (directed path) is a circuit {cycle) if the first and last vertex in the edgesequence are the same and all others distinct. The length of a path (directed path) is the sum of the weights of the branches (arcs) in it. A connected graph (digraph) is a graph (digraph) in which every pair of vertices is joined by a path. * Received July 13, 1971; revised version received October 9, 1971. This work was supported by the USAF Office of Scientific Research under Grant AFOSR-71-2103. 256 A. N. PATRIXOS AND S. L. HAKIMI A tree (directed, tree) is a connected graph (digraph) containing no circuits and thus any two vertices are joined by a unique elementary path. In directed trees not all vertices are joined by a directed path. In fact, if a directed path exists from t>< to , there is no directed path from i», to v, . In a tree, if each branch is replaced by two oppositely directed arcs, the digraph so constructed is a hypertree. Two such arcs in the hypertree form an elementary -pair, and the sum of the weights of the two arcs is the weight of the elementary pair. In a hypertree there is a unique elementary directed path between any pair of vertices. The distance d(v{ , y,-) of vertex t>,from vertex vt in a graph (digraph) is the length of a shortest (i.e. minimum sum of weights) elementary path (directed path) from v{ to v,-. Clearly d(v{ , vf) = d(Vj , i\) in graphs while in general d(v> , vf) ^ d{pi , v{) in digraphs. We also have d(v{ ,v{)=0 and d(v{, v,) = if there is no (directed) path from v{ to v,. A distance matrix D(V0 = [djy] of a graph (digraph) G = (F, B), Vi = [vkl , vk%, ■ ■ • , C7,isannXn matrix in which entry rf,-, (i, j = 1,2, , n) is the distance of vertex vkj from vertex vki(vti , vkj £ Fj). If v £ Fi then v is an external vertex, otherwise an internal vertex. Any vertex of degree one in a graph (digraph) is a terminal vertex. By a realization of an n X n matrix I) = [d,,] we mean a graph (digraph) G — (F, B), |F| > n, such that for some Fi Q V, |F,| = n, we shall have D(V,) = D. All graphs (digraphs) have distance matrices, graphs having symmetric ones and digraphs, in general, asymmetric ones. All entries in the distance matrix of a connected graph are finite. Connected digraphs may have infinite entries. A branch (arc) in a graph (digraph) is redundant if its removal results in a graph (digraph) with the same distance matrix. An internal vertex v in a graph (digraph) is redundant if it has deg (v, G) < 3 (indeg (v, G) < 2 or outdeg (v, G) < 2). The nullity of a connected graph (digraph) is equal to \B\ — |F| + 1 (|A| — |F| + 1) and thus is zero if the graph (digraph) is a (directed) tree. 2. Introduction. Given a weighted graph (digraph), algorithms are available for computing the distance matrix D of (a subset of) its vertices. Of these, the most efficient is due to Floyd [1], The algorithms fail, in general, if the graph has a branch with a negative weight or if the digraph has a cycle whose length is a negative number. A number of papers have also been published on the realizabilitv of a given n X n matrix D by a graph (digraph). Hakimi and Yau [2] gave necessary and sufficient conditions for an»X» symmetric matrix D with non-negative entries to be the distance matrix of a graph. They defined as 'optimum' that realization which has a minimum total sum of weights and proved that a tree realization, if one exists, is the unique optimum realization. Goldman [3] and Murchland [41 extended some of these results to digraphs. Generalizing the above results, we have proved that any (symmetric) square matrix with zero diagonal elements is the distance matrix of some (graph) digraph. Zaretskii [5, 6] gave necessary and sufficient conditions for the existence of a unique unweighted tree with n terminal vertices whose distance matrix equals a given matrix of order n. Simoes-Pereira [7] gave, without proof, a weaker statement of Theorem 2 presented in this work. Theorem 2 also provides a generalization of Zaretskii's results to the weighted case. Boesch [8], considering strictly non-negative weighted graphs, gave some properties of the distance matrix of a tree and suggested two algorithms for a tree realization. We indicate here that one of these algorithms (the one derived from theorem II of his work) can be successfully used in the general case. Shay [9] introduced the 'hypertree' and gave a necessary condition for its realization. We have completed his THE DISTANCE MATRIX OF A GRAPH 257 work on the hvpertree. Finally, we attacked the case of the distance matrix and its realization as a directed tree. Almost all previous work restricted itself to nou-negative entries in the given matrix D and non-negative weights in its realization. We have placed no such restriction in this work and admitted negative weights. Further, we introduce non-redundant internal vertices if they permit a realization which could not have been achieved otherwise. With these considerations in mind, the objectives of this paper are: 1. to find necessary and sufficient conditions for a given matrix to have a tree, hypertree or directed tree realization, 2. to find whether the above realizations are unique, 3. to indicate algorithms for construction of the tree, hypertree or directed tree if such realizations exist. 3. The distance matrix and its realizability. Given an n X n symmetric matrix D = [tZ,,], necessary and sufficient conditions for the existence of an ?;-vertex graph G with non-negative weights having D as its distance matrix were given by Hakimi and Yau [2], Specifically: 1) da = 0 for all i, 2) da + djk > dik for all i, j and k. The ?i-vertex graph G realizing I) can be constructed as follows: pick n vertices, labeling them Vi ,v2, ■ ■ ■ ,vn, and for every entry diS (i ^ j) of D draw a branch e(v{ , Vj) assigning to it the weight . Since du + dik > dik and dki + d,, > dki for any i, j and k we have du > 0. This implies that D must contain strictly non-negative entries. If no restriction is placed on the type of weights in a realization of D then we can state: Theorem 1: Any n X n symmetric matrix D = [fi,,] with zero diagonal elements is a distance matrix of some graph G. Proof: Consider the n X n matrix D' = [(/',], where d'a = dtj + a,+ a,if i ^ j = 0 if i = j and ak = max (max \{d,, — (drk + dk.)), \r, s = 1, 2, n If drk + dk, > dr, for some r, k and s then clearly d'rk + d'k, > d'r, . If drk + dk, < dr, for some r, k and s then 0 < §(c/r. — (dTk + dk,)) < ak , or (dr, + ar + a.) < (drk + ar + ak) + (dk, + ak + a,), or d'r, < d'rk + d'k, . Thus there exists an n-vertex graph G' which has D' as its distance matrix. Let G' be such a graph and v[ , v'2 , • • • , v'n be its vertices. To construct a graph G with distance matrix D add to G' vertex v, and connect it with v'i through a branch e(v,-, v[) of weight —a,(for all i). We have in G: d{v{ , v,) = d(vi , v') + d(v'{ , v'^ + d(v\ , = — a{ + d'f — a, = du (for all i and j). This proves the theorem. 4. The distance matrix and the tree realization. By virtue of Theorem 1 let us call a symmetric matrix D with zero diagonal elements a 'distance matrix'. We have proved that there exists at least one graph G realizing distance matrix D. If G[D] is the set of all 25S A. N. PATRINOS AND S. L. HAKIMI graphs realizing D we would like to know if there exists a tree I such that I £ G[D\. The following theorem provides an answer to this question. It was given by SimoesPereira [7] in a slightly weaker form. The interested reader should also consult Zaretskii [5, 6] for the unweighted case. Let us set <p(x, y, z) = 1 if at least two of the numbers x, y and z are equal. Since any 3X3 dist