Packing tree degree sequences

We consider special cases of the two tree degree sequences problem. We show that if two tree degree sequences do not have common leaves then they always have edge-disjoint caterpillar realizations. By using a probabilistic method, we prove that two tree degree sequences always have edge-disjoint realizations if each vertex is a leaf in at least one of the trees. This theorem can be extended to more trees: we show that the edge packing problem is in P for an arbitrary number of tree sequences with the property that each vertex is a non-leaf in at most one of the trees. We also consider the following variant of the degree matrix problem: given two degree sequences $D_1$ and $D_2$ such that $D_2$ is a tree degree sequence, decide if there exists edge-disjoint realizations of $D_1$ and $D_2$ where the realization of $D_2$ is not necessarily a tree. We show that this problem is already $\NP$-complete. Counting, or just estimating the number of distinct realizations of degree sequences is challenging in general. We show that efficient approximations for the number of solutions as well as an almost uniform sampler exist for two tree degree sequences if each vertex is a leaf in at least one of the trees.

of colors is two and the sum of the degrees on some of the vertices is less than n − 1. However, special cases that are computationally tractable are also of interest. A classical result of Kundu [6] shows that deciding if two tree degree sequences have edge disjoint realizations is in P.
Motivated by the aforementioned result, we consider special cases of the two tree degree sequences problem. We show that if two tree degree sequences do not have common leaves then they always have edge-disjoint caterpillar realizations. By using a probabilistic method, we prove that two tree degree sequences always have edge-disjoint realizations if each vertex is a leaf in at least one of the trees. This theorem can be extended to more trees: we show that the edge packing problem is in P for an arbitrary number of tree sequences with the property that each vertex is a non-leaf in at most one of the trees.
We also consider the following variant of the degree matrix problem: given two degree sequences D1 and D2 such that D2 is a tree degree sequence, decide if there exists edgedisjoint realizations of D1 and D2 where the realization of D2 is not necessarily a tree. We show that this problem is already NP-complete.
Counting, or just estimating the number of distinct realizations of degree sequences is challenging in general. We show that efficient approximations for the number of solutions as well as an almost uniform sampler exist for two tree degree sequences if each vertex is a leaf in at least one of the trees.

INTRODUCTION
Packing degree sequences is related to discrete tomography. The central problem of tomography is to reconstruct spatial objects from lower dimensional projections. The discrete 2D version is to reconstruct a colored grid from vertical and horizontal projections. In the simplest version, this problem is to reconstruct the coloring of an n × m grid with the requirement that each row and column has a specific number of entries for each color. Such colored matrix can be con-sidered as a factorization of the complete bipartite graph Kn,m. Indeed, for each color ci, the 0-1 matrix obtained by replacing ci to 1 and all other colors to 0 is an adjacency matrix of a simple bipartite graph such that the disjoint union of these simple graphs is Kn,m. The prescribed number of entries for each color are the degrees of the simple bipartite graphs. Therefore, an equivalent problem is to give a factorization of the complete bipartite graph into subgraphs with prescribed degree sequences.
It is also possible to consider the non-bipartite version of the graph factorization problem. Obviously, the sum of the degrees for each vertex must be n − 1 when the complete graph Kn is factorized. Therefore, if there are k degree sequences, the last degree sequence is uniquely determined by the first k − 1 degree sequences. When k = 2, the problem is reduced to the degree sequence problem, and can be solved in polynomial time [3,4]. When k = 3, the problem already becomes NP-complete [1]. However, special cases are polynomially solvable. Such a special case is when one of the degree sequences is almost regular, that is, any two degrees differ at most by 1 [5].
In this paper we consider the case when k = 3 and two of the degree sequences are tree degree sequences. It was already known that this case is tractable [6]. Here we present a new result considering special, caterpillar realizations. Another alternative proof is given for a special subclass of pairs of tree degree sequences that can be extended to an arbitrary number of sequences. The size of the solution space and sampling from it is also discussed. As a negative result, we show that deciding the existence of edge-disjoint realizations for two degree sequences D1 and D2 is NP-complete even if D2 is a tree degree sequence (but its realization do not have to be a tree).

PRELIMINARIES
In this section we give the definitions and lemmas needed to state the theorems. The central problem in this paper is the color degree sequence problem. Definition 1. A degree sequence D = d1, d2, . . . , dn is a series of non-negative integers. A degree sequence is graphical if there is a vertex labeled simple graph G in which the degrees of the vertices are exactly D. Such graph G is called a realization of D. The color degree matrix problem is the following: given a c × n degree matrix D = {{d1,1, d1,2, . . . , d1,n}, {d2,1, d2,2, . . . , d2,n}, . . . , {dc,1, dc,2, . . . , dc,n}}, in which each row of the matrix is a degree sequence, decide if there is an ensemble of edge disjoint realizations of the degree sequences. Such a set of edge disjoint graphs is called a realization of the degree matrix. Given two degree sequences D = d1, d2, . . . , dn and F = f1, f2, . . . , fn, their sum is defined as D + F = d1 + f1, d2 + f2, . . . , dn + fn.
For sake of completeness, we define tree degree sequences, path sequences and caterpillars.
Definition 2. Let D = d1, d2, . . . , dn be a degree sequence. Then D is called a tree sequence if n i=1 di = 2n − 2 and each degree is positive. If all of the degrees are 2 except two of them which are 1, then D is called a path sequence. A tree is a caterpillar if its non-leaf vertices span a path.
We will use the following complexity classes later on.  if there exists a randomized algorithm such that for any problem instance x, and , δ > 0, it generates an approximation f for the solution f , satisfying and the algorithm has a time complexity bounded by a polynomial of |x|, 1/ and − log(δ).
The total variational distance dT V (p, π) between two discrete distributions p and π over the set X is defined as Definition 5. A counting problem in #P is in FPAUS (Fully Polynomial Almost Uniform Sampler) if there exists a randomized algorithm such that for any instance x, and > 0, it generates a random element of the solution space following a distribution p satisfying where U is the uniform distribution over the solution space, and the algorithm has a time complexity bounded by a polynomial of |x| and − log( ).
The following technical lemma will be used later for constructing edge-disjoint caterpillar realizations. Lemma 1. For n ≥ 4, there exists two edge-disjoint Hamiltonian paths in the complete graph Kn whose ends are pairwise different.
Proof. Let V = {1, 2, . . . , n}, and let the first Hamiltonian path be 1, 2, 3 . . . , n. We are going to show by induction that there is a second Hamiltonian path H starting at 2, ending at 3 and using no edge between consecutive integers. For n = 4 the path H = 2, 4, 1, 3 does the job. Suppose n > 4 and we have a path H on vertices 1, . . . , n − 1 between 2 and 3. Since it has at least three edges, there is an edge ij where i, j < n − 1. Replace this edge by two edges in and nj for getting the desired path H.

PACKING TREES
First we consider the problem of packing two tree degree sequences without common leaves.
Proof. The proof is by induction on n. Observe that the smallest possible n is 4 to accommodate at least 4 = 2 × 2 leaves (note that each tree has at least two leaves). For n = 4, the only possible pair of degree sequences is (2, 2, 1, 1) and (1, 1, 2, 2). By Lemma 1, these sequences have edge disjoint realizations.
If n > 4 and both D and F are path sequences, then there exists edge disjoint Hamiltonian paths, according to Lemma 1.
So we may suppose that not both are path sequences. As the sum of the degrees in D + F is 4n − 4, there are at least four indices where dj + fj = 3, it is easy to check that we can select indices i and j such that, possibly after reversing D and F , we have di ≥ 3, dj = 1 and fj = 2.
Modify D and F by removing dj and fj and decreasing di by 1. This modified D and F are tree degree sequences without common leaves on n−1 vertices, therefore, by induction, D and F have edge disjoint caterpillar realizations, T 1 and T 2 . Modify T 1 and T 2 as follows. Add back vertex vj and connect it to vertex vi in T 1 . The so obtained T1 is a realization of D. Take a path P in T 2 containing all non-leaf vertices and two leaves. Observe that P has at least 3 edges, since otherwise F has n − 2 leaves, so D has only two, contradicting to di ≥ 3. Hence P has an edge v k v such that k = i and = i. For constructing T2, replace edge v k v of T 2 by two edges, v k vj and vjv . The tree T2 thus obtained is a caterpillar, edge disjoint from T1 and is a realization of F .
The theorem implicitly states that if two degree sequences do not share common leaves then their sum is graphical. If the two trees have common leaves, their sum is not necessarily graphical. The simplest example for it is the degree sequences Observe that the largest degree in D + F is 4, and there are only 3 vertices.
However, if their sum happens to be graphical then they also have edge disjoint realizations, as was shown by Kundu in [6].  However, there are tree degree sequences that have edge disjoint tree realizations but do not have edge disjoint caterpillar realizations. For example, consider the following tree degree sequences D = 5, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1 F = 5, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1 They have edge disjoint realizations, according to Theorem 3 (see also Fig. 1), since their sum is graphical. We claim that they do not have edge disjoint caterpillar realizations. To see this, observe that in any caterpillar realization, the degree 5 vertices must be connected to at least 3 leaves. However, there are only 5 vertices that are leaves in any of the trees, showing that any pair of caterpillar realizations will share at least one edge.
Theorem 2 considered the case when the leaf vertices of the degree sequences do not coincide. Now we turn to the opposite end, namely when each vertex is a leaf in at least one of the sequences.
Theorem 4. Let D = d1, d2, . . . , dn and F = f1, f2, . . . , fn be tree degree sequences such that min(di, fi) = 1 for all i. Let T1 and T2 be random realizations of D and F uniformly distributed. Then the expected number of common edges of T1 and T2 is 1.
Proof. The proof is based on the following lemma.
Lemma 5. Let T be a random realization of the tree degree sequence D = d1, d2, . . . , dn. Then the probability that there is an edge between vi and vj is Proof. It is well known that the number of trees with a given degree sequence is Let T denote those trees in which vi and vj are connected. Let f be a mapping from T to the trees with degree sequence d1, . . . , di−1, di+1, . . . , dj−1, dj+1, . . . , dn, di + dj − 2 obtained by joining vi and vj to a common vertex. The function f is surjective and each tree is an image d i +d j −2 times. Therefore the number of trees in which vi is connected to vj is The probability that vi and vj is connected is the ratio of (2) and (1), which is indeed thus concluding the proof of the lemma.
Now we turn to the proof of the theorem. Let D and F be the two degree sequences satisfying that each vertex is a leaf in at least one of the trees. Define Note that there might be parallel edges in the two trees only between these two sets. The expected number of parallel edges is then i∈A j∈B f j −1 n−2 = 1, since di = 1 for all i ∈Ā, fj = 1 for all j ∈B, and the sum of the degrees decreased by 1 is n − 2 for any tree degree sequence. This finishes the proof of the theorem. Theorem 4 implies a characterization of realizability for a subclass of tree degree sequences. Proof. If maxi{di} = n−1 or maxi{fi} = n−1 then D+ F is not graphical. On the other hand, if none of the trees is a star, then there are four distinct indices such that i1, i2 ∈ A and j1, j2 ∈ B. Then there exists a pair of trees T1 and T2 such that both trees contain edges (vi 1 , vj 1 ) and (vi 2 , vj 2 ) and T1 realizes D while T2 realizes F . Indeed, the degree 1 vertices can be connected to any of the non-leaf vertices. This means that there are trees having at least 2 common edges, which is above the average. Hence there must be a pair of trees with less than average number of common edges. That is, they are edge disjoint realizations. This theorem will be useful also at generating random realizations, see the next section.
Similar theorem holds for arbitrary number of tree sequences. We need a preliminary lemma (with V = {v1, . . . , vn}).
Proof. For any tree realization T , its restriction to U ∪Vj is a tree because outside U there are only leaves. In the case |U | > 2 we claim that there is a tree realization T such that its restriction to U is not a star. Indeed, if T restricted to U is a star centered at u ∈ U , then by the degree bound there is a leaf w ∈ L not connected u, call its neighbor u1 ∈ U . Let u2 be a third vertex of U . Replacing edges uu2 and u1w by edges u1u2 and uw gives another tree realization T , whose restriction to U is not a star.
For the case |U | = 2 let U = {vi, vj} and connect first v1 to vj. Now di + dj = n, so di ≥ m and dj ≥ m. For each k ≤ m − 1 connect one vertex of V k to vi and another one to vj. The remaining leaves in L can be distributed easily, connect any di − m of them to vi and the remainder to vj giving the aimed tree realization. Proof. Necessity is clear as D1 + D2 + · · · + Dm is not graphical if maxi,j{di,j} > n − m.
The statement is trivial when m = 1, if m = 2 then it is equivalent to Corollary 6, so we may suppose m > 2.
We give a constructive proof for the other direction. First a trial solution is built which might contain parallel edges, then these parallel edges are eliminated to get an edge disjoint realization.
Let Vi denote the subset of vertices on which the degrees in Di are larger than 1. Note that {V1, V2, . . . , Vm} forms a subpartition of V and |Vi| ≥ 2 for each i = 1, . . . , m. For a degree sequence Di, construct a trial treeTi by using Lemma 7, which ensures that the subtree on vertices Vi ∪ V k is a non-star tree for any k = i.
From the trial solution, which might contain several parallel edges, a final solution is built in the following way. While there exists a pair of indexes (i, k) such that there is one or more parallel edges between Vi and V k , do the following. LetT i,k denote the subtree of the treeTi on vertices Vi ∪ V k and letD i,k denote its degree sequence. By Corollary 6, D i,k andD k,i have edge disjoint tree realizations. Replacẽ T i,k andT k,i by such realizations. This removes all parallel edges between Vi and V k becauseTj has no edge between these sets if j = i, j = k.

COUNTING AND SAMPLING REALIZA-TIONS
Since typically there are more than one realizations when a realization exists, and typically the number of realizations might grow exponentially, is is also a computational challenge to estimate their number and/or sample almost uniformly a solution. Here we have the following theorem.
Theorem 9. Let D = d1, d2, . . . , dn and F = f1, f2, . . . , fn be two tree degree sequences such that each vertex is a leaf in at least one of the trees. Furthermore, assume that none of the trees is a star. Then there is an FPRAS for estimating the number of disjoint realizations and there is an FPAUS for almost uniformly sampling realizations.
Proof. This theorem is based on Theorem 4. As we discussed, there are random trees with at least two parallel edges. The number of pair of trees containing parallel edges (vi 1 , vj 1 ) and (vi 2 , vj 2 ) such that di 1 , di 2 > 1 and fj 1 , fj 2 > 1 is Therefore, at least the same number of pair of trees have no parallel edges (that is, are edge disjoint realizations of the degree sequences) to get the expectation 1 for the number of parallel edges. Therefore, the probability that two random trees will be edge disjoint is at least It follows from basic statistical considerations that an FPRAS algorithm can be designed based on this property. Indeed, let ξ be the indicator variable that a random pair of trees are edge disjoint realizations. Then the number of edge disjoint realizations is Furthermore, we know that Uniformly distributed random trees with a prescribed degree sequence can be generated in polynomial time based on the fact that the probability that a given leaf is connected to a vertex with degree di is A uniformly distributed tree can be generated by randomly selecting a neighbor of a given leaf, then generating a random tree for the remaining degree sequence. Equivalently, the trees with a prescribed degree sequence can be encoded by the Prüffer codes in which the index i appears exactly di − 1 times. Uniformly generating such Prüffer codes is an elementary computational task.
Therefore, random pair of trees can be generated in polynomial time, and it is easy to check whether or not they are edge disjoint realizations. Such sampling of random trees provide an unbiased estimation for the expectation of the indicator variable ξ. Indeed, if Xi is 1 if the i th pair of random trees are edge disjoint and 0 otherwise, then the random variable Xi follows a binomial distribution with parameter p = E[ξ] and expectation mE [ξ]. The tails of the binomial distributions can be bounded by the Chernoff's inequality: This should be bounded by δ 2 (the other half δ error will go to the other tail) Solving Equation 4, we get For the upper tail, we can also use the Chernoff's inequality, just replacing p with 1−p and the upper threshold mp(1+ ) with m − mp(1 + ): Upper bounding this with δ 2 and solving the inequality, we get that Since 1 p = O(n 4 ), the necessary number of samples is indeed polynomial with the size of the problem, 1 e and − log(δ). Furthermore, one sample can be generated in polynomial time, therefore this algorithm is indeed an FPRAS.
It is also well known that an FPAUS algorithm can be designed in this case. The FPAUS algorithm generate − log( ) p pair of random trees. If any of them is an edge disjoint realization, then the algorithm returns with it. Otherwise it generates an arbitrary realization and returns with it. This is indeed an FPAUS algorithm, since any random pair of trees which are edge disjoint come from sharp the uniform distribution of the solutions. The probability that there will be no edge disjoint pair of trees in m number of samples is This probability is not larger than . Indeed, Namely, the algorithm generates realizations from a distribution which is the convex combination (1− )U + π, where ≤ , U is the uniform distribution and π is an arbitrary distribution. However, the variational distance of this distribution from the uniform one is Since one sample can be generated in polynomial time, and the total number of samples is polynomial with the size of the problem and − log( ), this algorithm is indeed and FPAUS.
It remains an open question whether or not similar theorems exist for the case when the tree degree sequences have common high degrees. Also it is open if exact counting of the edge disjoint solutions is possible in polynomial time, although the natural conjecture is that this counting problem is #P-complete.

AN NP-COMPLETENESS THEOREM
What can we say when only one of the two degree sequences is a tree degree sequence and the other is arbitrary? Unfortunately, we have a negative result here.
Theorem 10. It is NP-complete to decide if there is an edge disjoint realization of a tree degree sequence and an arbitrary degree sequence. (It is not required that the tree degree sequence have a tree realization).
Proof. We use the theorem by [1] that it is NP-complete to decide if two bipartite degree sequences has an edge disjoint realizations. We have the following observations.
• The degree sequence pair D = d1, d2, . . . , dn and F = f1, f2, . . . , fn has an edge disjoint realization if and only if the degree sequence pair D = d1 + 1, d2 + 1, . . . , dn + 1, n and F = f1, f2, . . . , fn, 0 has an edge disjoint realization. Indeed, let G1 and G2 be an edge disjoint realization of D and F . Then add a vertex vn+1 to G1, and connect it to all the other vertices to get a realization of D . Add an isolated vertex vn+1 to G2 to get a realization of F . These realizations of D and F are edge disjoint. On the other hand, in any realization of D , vn+1 is connected to all the other vertices. If edge disjoint realizations of D and F are given, delete vn+1 from both realizations to get edge disjoint realizations of D and F .
On the other hand, in any edge disjoint realizations G 1 and G 2 of D and F , vn+1 is connected to all v1, . . . , vn in G 2 , therefore, vn+1 must be connected to vn+2 in G 1 . Therefore deleting vn+1 and vn+2 yields an edge disjoint realization of D and F .
We can use the first observation to prove that it is also NPcomplete to decide that two simple degree sequences have edge disjoint realizations. The second observation provides that it is NP-complete to decide if two degree sequences have edge disjoint realizations such that one of the degree sequences does not have 0 degrees. Finally, we can use the third observation to iteratively transform any D degree sequence (that already does not have a 0 degree) to a tree degree sequence. Indeed, in each step, we add two vertices to D and extend the sum of the degrees only by 2. Therefore in a polynomial number of steps, we get a degree sequence D in which the sum of the degrees is exactly twice the number of vertices minus 2. Therefore it follows that given any bipartite degree sequences D and F , we can construct in polynomial time two simple degree sequences D and F such that D and F have edge disjoint realizations if and only if D and F have edge disjoint realizations, furthermore, D is a tree degree sequence.

DISCUSSION AND CONCLUSIONS
In this paper, we considered packing tree degree sequences. When there are no common leaves, there are always edge disjoint caterpillar realizations. On the other hand, there might not be edge disjoint caterpillar realizations when there are common leaves, even if otherwise there are edge disjoint tree realizations.
When there are no common high degree vertices, there are edge disjoint tree realizations if and only if none of the degree sequences is a degree sequence of a star. Similar theorem exists for arbitrary number of trees, and it is easy to decide if arbitrary number of tree degree sequences without common high degrees have edge disjoint realizations.
It is also known [5] that a degree sequence and an almost regular degree sequence have an edge disjoint realization if and only if their sum is graphical. This raises the natural question if a degree sequence and a tree sequence have edge disjoint realizations if and only if their sum is graphical. We showed that the answer is no to this question, and actually, it is NP-complete to decide if an arbitrary degree sequence and a tree degree sequence have edge disjoint realizations.
We also considered to approximately count and sample edge disjoint tree realizations with prescribed degrees. We showed that it is possible if there are no common high degree vertices.
It remains an open question when the two degree sequences have common high degree vertices.