Efficiently Realizing Interval Sequences

We consider the problem of realizable interval-sequences. An interval sequence comprises of $n$ integer intervals $[a_i,b_i]$ such that $0\leq a_i \leq b_i \leq n-1$, and is said to be graphic/realizable if there exists a graph with degree sequence, say, $D=(d_1,\ldots,d_n)$ satisfying the condition $a_i \leq d_i \leq b_i$, for each $i \in [1,n]$. There is a characterisation (also implying an $O(n)$ verifying algorithm) known for realizability of interval-sequences, which is a generalization of the Erdos-Gallai characterisation for graphic sequences. However, given any realizable interval-sequence, there is no known algorithm for computing a corresponding graphic certificate in $o(n^2)$ time. In this paper, we provide an $O(n \log n)$ time algorithm for computing a graphic sequence for any realizable interval sequence. In addition, when the interval sequence is non-realizable, we show how to find a graphic sequence having minimum deviation with respect to the given interval sequence, in the same time. Finally, we consider variants of the problem such as computing the most regular graphic sequence, and computing a minimum extension of a length $p$ non-graphic sequence to a graphic one.


Introduction
The Graph Realization problem for a property P deals with the following existential question: Does there exist a graph that satisfies the property P ? Its fundamental importance is apparent, ranging from better theoretical understanding, to network design questions (such as constructing networks with certain desirable connectivity properties). Some very basic, yet challenging, properties that have been considered in past are degree sequences [9,18,20], eccentricites [6,24], connectivity and flow [16,12,10,11].
One of the earliest classical problems studied in this domain is that of graphic sequences. A sequence of n positive integers, D = (d 1 , . . . , d n ), is said to be graphic if there exists an n vertex graph G such that D is identical to the sequence of vertex degrees of G. The problem of realizing graphic sequences and counting the number of non-isomorphic realizations of a given graphic-sequence, is particularly of interest due to many practical applications, see [27] and reference therein. In 1960, Erdös and Gallai [9] gave a characterization (also implying an O(n) verifying algorithm) for graphic sequences. Havel and Hakimi [18,20] gave a recursive algorithm that given a sequence D of integers computes a realizing graph, or proves that the sequence is non-graphic, in optimal time O( i d i ). Recently, Tripathi et al. [28] provided a constructive proof of Erdös and Gallai's [9] characterization.
We consider a generalization of the graphic sequence problem where instead of specifying precise degrees, we are given a range (or interval) of possible degree values for each vertex. Formally, an intervalsequence is a sequence of n intervals S = ([a 1 , b 1 ], . . . , [a n , b n ]), also represented as S = (A, B), where A = (a 1 , . . . , a n ) and B = (b 1 , . . . , b n ), and 0 ≤ a i ≤ b i ≤ n − 1 for every i. It is said to be realizable Theorem 1. There exists an algorithm that for any integer n ≥ 1 and any length n interval sequence S, computes a graphic sequence D realizing S, if exists, in O(n log n) time.
Moreover, our algorithm can also output in the same time graphic certificates corresponding to a sparsest as well as densest possible graph (i.e. graphs with minimum and maximum possible edges), realizing S.
We also investigate the problem of efficiently computing graphic sequences having the least possible L 1 -deviation in the scenario when the input interval sequence is non-realizable. We must point out here that till now there was also no sub-quadratic time algorithm known for computing even the deviation δ(D, S). Our result for deviation minimizing certificate can be formalized as follows.
Theorem 2. There exists an algorithm that for any integer n ≥ 1 and any length n non-realizable interval sequence S, outputs in O(n log n) time a graphic sequence D minimizing the deviation δ(D, S).
Our new approach enables us to tackle also an optimization version of the problem in which it is required to compute the "most regular" sequence realizing the given interval sequence S, using the natural measure of the minimum sum of pairwise degree differences, i,j |d i − d j |, as our regularity measure. To the best of our knowledge, this problem was not studied before and is not dealt with directly by the existing approaches to the interval sequence problem. Specifically, we obtain the following. Theorem 3. There exists an algorithm that for any integer n ≥ 1 and any length n realizable interval sequence S, computes the most regular graphic sequence realizing interval sequence S (i.e., the one minimizing the sum of pairwise degree difference), in time O(n 2 ).
The tools developed in this paper allows us to study other interesting applications, such as computing a minimum extension of non-graphic sequences to graphic ones (see Section 6).
Related work. Kleitman and Wang [23], and Fulkerson-Chen-Anstee [2,8,14] solved the problem of degree realization for directed graphs, wherein, for each vertex both the in-degree and out-degree is specified. In [19], Nichterlein and Hartung proved the NP-completeness of the problem when the additional constraint of acyclicity is imposed. Over the years, various extensions of the degree realization problems were studied as well, cf. [1,30]. The Subgraph Realization problem considers the restriction that the realizing graph must be a subgraph (factor) of some fixed input graph. For an interesting line of work on graph factors, refer to [29,3,21,17]. The subgraph realization problems are generally harder. For instance, it is very easy to compute an n-vertex connected graph whose degree sequence consists of all values 2, however, the same problem for subgraph-realization is NP-hard (since it reduces to Hamiltoniancycle problem).
Lesniak [24] provided a characterization for the sequence of eccentricities of an n-vertex graph. Behzad et al. [6] studied the problem of characterizing the set comprising of vertex-eccentricity values of general graphs (the sequence problem remains open). Fujishige et al. [13] considered the problem of realizing graphs and hypergraphs with given cut specifications. Realization problems related to various criteria of relative satisfaction are considered in [5]. Several other realization problems are surveyed in [4].
Organization of the Paper. In Section 2, we present the notation and definitions. In Section 3, we discuss the main ideas and tools that help us to construct graph certificates for interval sequence problem. Section 4 presents our O(n log n) time algorithm for computing graphic certificate with minimum deviation. Section 5 provides a quadratic-time algorithm for computing the most regular certificate. We discuss the applications in Section 6. The appendix includes linear time verification algorithms implied by the work of Erdös and Gallai [9], and Cai et al. [7].

Preliminaries
A sequence is defined to be an n-element vector whose entries are non-negative integers. For any sequence and parity(D) = sum(D) mod 2. Given any two sequences X = (x 1 , . . . , x n ) and Y = (y 1 , . . . , y n ), we say that X ≤ Y if x i ≤ y i for 1 ≤ i ≤ n. Any two sequences X and Y are said to be similar if they are identical up to permutation of the elements (i.e., their sorted versions are identical). A sequence D is said to lie in an interval-sequence (A, B), denoted by D ∈ (A, B), if A ≤ D ≤ B. We define min(X, Y ) = (min{x 1 , y 1 }, . . . , min{x n , y n }), and max(X, Y ) = (max{x 1 , y 1 }, . . . , max{x n , y n }). The L 1 -distance of the pair (X, Y ) is defined as Denote by and ⊥ the n-length sequences all whose entries are respectively n − 1 and 0. Given a sequence D = (d 1 , . . . , d n ) and an integer k ∈ [1, n], define the vectors X(D) and Y (D) by setting for 1 ≤ k ≤ n: The deviation of D is defined as δ(D, S) = δ U (D, S) + δ L (D, S). For any vertex x in an undirected simple graph H, define deg H (x) to be the degree of x in H, and define N H (x) = {y | (x, y) ∈ E(H)} to be the neighbourhood of x in H.
We next state the Erdös and Gallai [9] characterisation for realizable (graphic) sequences, and Cai et al. [7] characterisation for realizable interval sequences. An O(n)-time implementation of the both theorems is provided in the Appendix A.

Main Tools
In this section, we develop some crucial tools that help us in efficient computation of certificate for a realizable interval-sequence. These tools will help us to search a graphic sequence in O(n log n) time using a clever divide and conquor methodology. Also they aid in searching for the maximally regular sequence in just quadratic time.
We now discuss some properties of levelling operations.
Lemma 1. Any levelling operation on a sequence D that results in a non-similar sequence, reduces its spread φ(D) by a value at least two.
Proof. Let D = (d 1 , d 2 , . . . , d n ) and Z = (z 1 , . . . , z n ) = π(D, α, β), be a sequence obtained from D by performing a levelling operation on a pair of indices α, β such that d α > d β . If d α = d β + 1, then it is easy to verify that D and Z are similar. If d α ≥ d β + 2, then Thus, the claim follows.
Lemma 2 (Corollary 3.1.4, [26]). The levelling operations preserves graphicity, that is, if we perform a levelling operation on a graphic sequence, then the resulting sequence is also graphic.
then D * is similar to D, and thus also graphic. So for the rest the proof let us focus on the case d α ≥ 2 + d β . Let G = (V, E) be a graph realising the sequence D, and let x α and x β be two vertices in G having degrees respectively d α and d β .
be a graph obtained from G by deleting the edge (w, x α ), and adding a new edge (w, x β ). Observe that the degree of all vertices other than x α and x β are identical in graphs G and G * , also Therefore G * is a graph realising the profile D * , and thus the claim follows.
Levelled sequences. A sequence D is said to be levelled with respect to the integer-sequence S = (A, B) if (i) A ≤ D ≤ B, and (ii) the spread of D cannot be decreased by a levelling operation, i.e., for any two indices α = β satisfying d α > d β and A ≤ π(D, α, β) ≤ B, we have φ(π(D, α, β)) = φ(D). See Figure 1.
The volume of a sequence D lying between A and B with respect to S = (A, B) is defined as and is invariant of levelling operations applied to D. In other words, applying a levelling operation to a sequence D may reduce its spread but preserves its volume. Note that the volume lies in the range Proof. By Lemma 1, every levelling operation that results in a new (non-similar) sequence decreases the spread by at least two. Since the spread of any sequence D is always non-negative and finite (specifically, O(n 3 )), it is possible to perform (O(n 3 )) levelling operations on D so that the resultant sequence D * is levelled. Since the levelling operation preserves the volume, VOL(D * , S) must be same as VOL(D, S).
Any graphic sequence D realizing the interval sequence S = (A, B) by Lemma 3 can be altered by O(n 3 ) levelling operations to obtain a levelled sequence lying between A and B. The resultant sequence by Lemma 2 remains graphic, thus the following theorem is immediate.
Observe that F (·, S) is a non-decreasing function in the range (min(A), max(B)). Hence we may define the corresponding inverse function as We conclude this section by providing the following theorems for characterising and computing levelled sequences. Proof. We first make some observations about levelled sequences. Let D = (d 1 , . . . , d n ) be a levelled sequence with respect to S = (A, B) having volume L, then Then one can perform a levelling operation on the pair (i 0 , j 0 ), to obtain a new sequence D * that lies between A and B, and has spread φ strictly less than that of sequence D. This contradicts the fact that D was levelled. So let us assume For i 0 we have Combining above two inequalities, we get where the inequality follows from the fact that , then index i 0 contributes a positive value of d i 0 − a i 0 to the first sum and zero to the second.) This violates the fact that F is non-decreasing. The proof of claim (ii) follows in similar manner as that of claim (i), and is thus omitted.
We now show that each levelled sequence D w.r.t. S satisfies conditions (a), (b) and (c). We show that for any i satisfying b i ≤ (or equivalently, b i ≤ ), d i = b i . To prove this, let us assume to the contrary that Similarly, it follows that for any i satisfying a i ≥ (or equivalently,    It is not hard to verify that = F −1 (L, S). Thus a levelled sequence of volume L can be computed in O(n) time using Theorem 7. In Algorithm 1 we present the pseudocode of our implementation that can be seen as filling the vessels with fluid until reaching the desired level .
The correctness of Algorithm 1 follows from above description, also it is easy to verify that the total run-time of the algorithm is O(n).

An O(n log n) time algorithm for Graphic Certificate
In this section, we present an algorithm for computing a certificate for interval sequence that takes just O(n log n) time. If the input interval S = (A, B) is realizable, our algorithm computes a graphic sequence D ∈ S, otherwise it computes a sequence minimizing the deviation value δ(D, S). We begin by considering the case where the sequence S is realizable (since it is simpler to understand given Theorems 7 and 8), and then we move to the case where S is non-realizable. Then characterization of [7] implies an O(n) time verification algorithm for realizability of interval sequence. (For details refer to the Appendix).

Realizable Interval Sequences
First we show that any two levelled sequences after an appropriate reordering of their elements are coordinatewise comparable. = (A, B), and any two levelled sequences C, D ∈ S satisfying VOL(D, S) ≤ VOL(C, S), the following holds.

Lemma 4. For any interval sequence S
1. D ≤ C, for some sequence D ∈ S similar to D.
2. D ≤ C , for some sequence C ∈ S similar to C.
Proof. We show how to transform D = (d 1 , · · · , d n ) into sequence D = (d 1 , · · · , d n ) ∈ S such that D ≤ C. Let D = F −1 (VOL(D, S), S) and C = F −1 (VOL(C, S), S). Since F (·, S) is a non-decreasing function, we have that D ≤ C . Let us first consider the case where C and D are both non-integral, and C = D = (say 1 ) and C = D = (say 2 ). By Theorem 7, for any . Therefore, for each index i, d i ≤ c i . So in this case, we set D to be D. The construction of sequence C follows similarly.
Next lemma shows significance of partitioning an interval-sequence using a levelled sequence. Proof. We provide proof of the case L D ≤ L C (the proof of part (b) will follow in a similar fashion). By Lemma 4, we can transform D = (d 1 , · · · , d n ) into another levelled sequence D = (d 1 , · · · , d n ) ∈ S such that D is similar to D and D ≤ C. Since D ≤ C, and D is a graphic sequence, it follows that (A, C) is realizable interval sequence.
From Lemma 5, and the fact that each realizable interval-sequence contains a levelled graphic sequence (see Theorem 6), we obtain following.
Theorem 9. For any realizable interval sequence S = (A, B), and any levelled sequence C ∈ S, at least one of the interval-sequences (A, C) and (C, B) is realizable.
The above theorem provides a divide-and-conquer strategy to search for a levelled graphic sequence for realizable interval-sequences as shown in Algorithm 2. Let (A 0 , B 0 ) be initialized to (A, B). We compute a levelled sequence C 0 having volume L 1 (A 0 , B 0 )/2 using Theorem 7. It follows from Theorem 9, either (A 0 , C 0 ) or (C 0 , B 0 ) must be a realizable interval-sequence. If (A 0 , C 0 ) is realizable then we replace B 0 by C 0 ; otherwise (C 0 , B 0 ) must be realizable, so we replace A 0 by C 0 . We continue this process (of replacements) until L 1 (A 0 , B 0 ) decreases to a value smaller than 2. In the end, the interval sequence (A 0 , B 0 ) contains at most two sequences, namely A 0 and B 0 . If A 0 is graphic then we return A 0 , otherwise we return B 0 . The correctness of the algorithm is immediate from the description. It is also easy to verify that the algorithms outputs a graphic-certificate with the least possible number of edges.
To analyze the running time, observe that the L 1 -distance between A 0 and B 0 decreases by (roughly) a factor of 2 in each call of the while loop, so it follows that number of iterations is O(log n). Verifying if an interval sequence is realizable, or a sequence D is graphic can be performed in O(n) time, using Theorem 11. Also in O(n) time we can generate a levelled sequence of any given volume L by Theorem 8. Thus, the total time complexity of the algorithm is O(n log n).
We obtain the following result: There exists an algorithm that for any integer n ≥ 1 and any n-length interval sequence S = (A, B), computes a graphic sequence D ∈ (A, B), if it exists, in O(n log n) time. Moreover, our algorithm can also output graphic certificates corresponding to a sparsest and densest 3 possible graph (i.e. having minimum and maximum possible edges), realizing S, in the same time.

Non-Realizable Sequences
In this subsection we consider the scenario where S is non-realizable, our goal is to compute a graphic sequence D minimizing the deviation δ(D, S) with respect to the given interval sequence S.
As a first step, we show that in order to search a sequence D minimizing δ(D, S), it suffices to search a sequence D ≥ A that minimizes the value δ U (D, S).  By the previous lemma, our goal is to find a graphic sequence D in the interval sequence (A, ) minimizing δ(D, S). Notice that if D is graphic, then the interval sequence (A, R), where R = max (D, B), is realizable. Also, δ(D, S) = sum(R − B). Hence, in order to compute a graphic sequence with minimum deviation, we define R to be the set of all sequence R ∈ [B, ] such that (i) the interval sequence (A, R) is realizable, and (ii) sum(R − B) is minimized.
The following lemma shows the significance of the set R in computing a certificate with minimum deviation. Next, let R L be the set of all levelled sequences in R with respect to interval sequence (B, ).
Proof. Clearly, R = ∅. Consider any sequence R = (r 1 , . . . , r n ) ∈ R. Suppose there exists α, β ∈ [1, n] such that r α − r β ≥ 1 and R = π(R, α, β) Since levelling operation preserves graphicity, D is graphic. Thus R ∈ R, which shows that R is closed under the levelling operation, and hence R L is non-empty. The running time analysis is similar to the one for Algorithm 2. Since the L 1 -distance between M 1 and M 2 decreases by a factor of 2 in each successive call of the while loop of the algorithm, it follows that number of times the while loops run is O(log n). Verifying if an interval sequence is realizable, or a sequence D is graphic can be performed in O(n) time, using Theorem 11. Also it takes O(n) time to generate a levelled sequence of any given volume L by Theorem 8. Finally, the running time of Algorithm 2 is O(n log n). Thus, the total time complexity of algorithm is O(n log n).
This completes the proof of Theorem 1.

Most Regular Certificate in O(n 2 ) time
In this section, we present an O(n 2 )-time algorithm for computing a most-regular certificate with respect to a given interval sequence S = (A, B). We assume that S is realizable. Our algorithm involves a subroutine that given an integer z ∈ [min(A), max(B) − 1], computes a most-regular graphic-sequence, say D, satisfying the condition z ≤ = F −1 (VOL(D, S), S) ≤ z + 1. The following lemma is immediate from Theorem 7. We partition the set [1, n] into three sets I 1 , I 2 , I 3 such that I 1 = {i ∈ [1, n] | a i ≥ z + 1}, I 2 = {i ∈ [1, n] | a i ≤ z and z + 1 ≤ b i }, and I 3 = {i ∈ [1, n] | b i ≤ z}. Also, using integer sort in linear time, we rearrange the pairs in (A, B) along with the corresponding sets I 1 , I 2 , I 3 so that (i) for any i ∈ I 1 , j ∈ I 2 , k ∈ I 3 , we have i < j < k, and (ii) the sub-sequences A[I 1 ] and B[I 3 ] are sorted in the non-increasing order.
We initialize D z = (d z,1 , d z,2 , . . . , d z,n ) by setting d z,i to : a i if i ∈ I 1 , z if i ∈ I 2 , and b i if i ∈ I 3 . The sequence D z is sorted in non-increasing order, since the sub-sequences A[I 1 ] and B[I 3 ] are sorted in non-increasing order. Let α = |I 1 | and β = |I 1 | + |I 2 |, so that I 2 = [α + 1, α + 2, . . . , β]. We would search all those indices i ∈ [α, β] such that on incrementing d α+1 , . . . , d i to value z + 1, the resulting sequence is graphic; or equivalently, the sequence D z + E [α+1,i] is graphic. Note that for any index i ∈ [α, β], (i) the sequence D z + E [α+1,i] is non-increasing, and (ii) A ≤ D z + E [α+1,i] ≤ B. The next lemma, which follows from the definition of φ, will be used to compute φ(D z + E [α+1,i] ) from φ(D z ).

Lemma 10. For any index
and the lemma follows.
For each z we compute the vectors X(D z ) and Y (D z ) using Theorem 11 in the Appendix. For each integer k ∈ [1, n], let Proof. For each k ∈ [1, n], let We fix an index k ∈ [1, n] for the rest of the proof. Our goal will be to show that the set AVOID(k) is the union of the interval AVOID 1 (k) and AVOID 2 (k), and is thus computable in O(1) time. Consider any i ∈ [α, β] ∩ [1, k]. Since α ≤ i ≤ k, we have that It follows that Next consider any i ∈ [α, β] ∩ [k, n]. As k ≤ i ≤ β, we have that We have the following three different cases: , implying that i ∈ AVOID 2 (k). Therefore, in this case AVOID 2 (k) = [α, β] ∩ [k, n].
Case 3: k ≥ z + 1: The lemma follows. Algorithm 4 presents the procedure for computing the most-regular certificate. For each k ∈ [1, n], AVOID(k) is a contiguous sub-interval of [1, n], therefore, the union AVOID = n k=1 AVOID(k) can be computed in linear time using simple stack based data-structure, once the intervals are sorted in order of their endpoints 4 using integer sort. Let I z denote the set obtained by removing from [α, β] \ AVOID each index i

Applications and Extensions
In this section, we discuss some related problems whose solutions follow as immediate application of our interval sequence work.
Solution: Let M denote the value max(A) = max i∈ [1,p] a i . For any n ≥ p, let S n = ([a 1 , a 1 ], . . . , [a p , a p ], [1, n], . . . , [1, n]) denote the sequence obtained by appending n − p copies of interval [1, n] to interval sequence (A, A). Let n 0 the denote the length of a minimum graphic extension of A. Observe that n 0 ∈ [max{p, M }, p + M ]. The lower limit is due to the fact that the length of minimum graphic extension of A must be at least max{p, M }; the upper limit holds since one can have a bipartite graph with partitions X = {x 1 , . . . , x p } and Y = {y 1 , . . . , Y M } of length p and M , and for i ∈ [1, p], connect the vertex x i to vertices y 1 , . . . , y a i . It turns out that we need to find the smallest integer n ∈ [max{p, M }, p + M ] such that S n is graphic. The minimum n can be obtained by a binary search over the range [max{p, M }, p + d] and using Theorem 5; this takes O(max{p, M } log max{p, M }) time. Once n 0 is known, the optimal graphic extension can be computed using Theorem 10 for searching graphic certificate in O(max{p, M } log max{p, M }) time.
Problem 2. Given A = (a 1 , . . . , a n ), find a graphic sequence D = (d 1 , . . . , d n ) whose chebyshev distance (L ∞ distance) from A is minimum. Solution: The above problem can be reduced to interval sequence problem, as we need to find smallest non-negative integer c ∈ [1, n] such that S c = ([a 1 − c, a 1 + c], . . . , [a n − c, a n + c]) is realizable. To find the minimum c, we do a binary search with help of Theorem 5 for verification; this takes O(n log n) time. Once optimal c is known, the sequence D can be computed using Theorem 10 to search graphic certificate in S c , thus the time complexity for computing sequence D is O(n log n). A = (a 1 , . . . , a n ), find minimum fraction and a graphic sequence D = (d 1 , . . . , d n ) satisfying a i (1 − ) ≤ d i ≤ a i (1 + ).

Problem 3. Given
Solution: Again we need to find smallest non-negative fraction such that the interval sequence S = ([a 1 (1 − ), a 1 (1 + )], . . . , [a n (1 − ), a n (1 + )]) is realizable. To find the minimum , we do a binary search with help of Theorem 5; this takes O(n log n) time. Once is known, using Theorem 10, sequence D can be computed in O(n log n) time.