3
Volume 12, number 1 INFOKMMIOlU PROCESSING-LE&ERS A LINEAR-TIME RECOGNITION ALGORITHM FOR INTERVAL DAGS * Harold N. GABOW Departmentof Computer Science, University of Colorado at Boulder, Boulder, CO 89309, U.S.A. Received 17 July 1980; revised version received 27 October 1980 Scheduling, dag, interval order, transitive closure 1. Introduction In [4], Papadimitriou and Yannakakis solve the unit-execution-time scheduling problem [ 1, pp. 5 I- 53] for a famiiy of partial orders called interval orders. Only one other family (the forest orders [2]) is known to have an efficient solution. Q, = To C T1 5 0.0 Ct TQ_~S To. Fig. 1 &OWS UI inter- val dag. The transitively closed interval dags are exactly the interval orders; this can be seen by examining the proofs of [4]. The development in [4] assumes the interval order is given in transitively closed form. This note extends ideas +&at are implicit in [4] to remove this assump tion. The main tool is a linear-time algorithm to recog- nize an interval dag, i.e., a dag whose transitive closure is an interval order. This is given in Section 2. Section 3 indicates how the recognition algorithm applies to the scheduling problem. 2. The recognition algorithm The algorithm processes vertices one-by-one, checking the nesting property is always satisfied. To do this, the vertices are numbered in topological order [3), so if (i, j) is an edge, i < j. (Each vertex is identi- fied with its number.) Vertices are processed in decrea$ng order. Before proceeding we establish some notation and give a convenient definition of interval dag. For a dag (directed acyclic graph), n represents the number of vertices and m the number of edges; the vertices are numbered 1, .... n. For a vertex i, the set of vertices adjaent,%m i is A(i) = 0 1 there is an edge from i to j}; the access0r set of i is S(i) = $1 there is a path of one or more edges from i to j). An interval dag satisfies the following nestingprop- erty : Suppose the nesting property has been verified for all vertices j > i. So the distinct successor sets S(j), j’> i, can be labelled as To 5 l .05 Tk_1 s Tk, where for convenience, Tk does not denote a successor& but rather Tk = {1, *..,n). Let Ts be the smallest set containing A(i). The nesting property implies T,_i s Definition. A dag is an interval ‘&g iff for any two vertices i, j, either S(i) c S(j) or S(j) E S(i). So the distinct successor sets S(j) can be labelled as * This research was supported in part by National Science Fouxidation Grant MCS78-18909. 20 Fig. 1. Examplkgraph.

A linear-time recognition algorithm for interval dags

Embed Size (px)

Citation preview

Page 1: A linear-time recognition algorithm for interval dags

Volume 12, number 1 INFOKMMIOlU PROCESSING-LE&ERS

A LINEAR-TIME RECOGNITION ALGORITHM FOR INTERVAL DAGS *

Harold N. GABOW Department of Computer Science, University of Colorado at Boulder, Boulder, CO 89309, U.S.A.

Received 17 July 1980; revised version received 27 October 1980

Scheduling, dag, interval order, transitive closure

1. Introduction

In [4], Papadimitriou and Yannakakis solve the unit-execution-time scheduling problem [ 1, pp. 5 I- 53 ] for a famiiy of partial orders called interval orders. Only one other family (the forest orders [2]) is known to have an efficient solution.

Q, = To C T1 5 0.0 Ct TQ_~ S To. Fig. 1 &OWS UI inter- val dag. The transitively closed interval dags are exactly the interval orders; this can be seen by examining the proofs of [4].

The development in [4] assumes the interval order is given in transitively closed form. This note extends ideas +&at are implicit in [4] to remove this assump tion. The main tool is a linear-time algorithm to recog- nize an interval dag, i.e., a dag whose transitive closure is an interval order. This is given in Section 2. Section 3 indicates how the recognition algorithm applies to the scheduling problem.

2. The recognition algorithm

The algorithm processes vertices one-by-one, checking the nesting property is always satisfied. To do this, the vertices are numbered in topological order [3), so if (i, j) is an edge, i < j. (Each vertex is identi- fied with its number.) Vertices are processed in decrea$ng order.

Before proceeding we establish some notation and give a convenient definition of interval dag. For a dag (directed acyclic graph), n represents the number of vertices and m the number of edges; the vertices are numbered 1, . . . . n. For a vertex i, the set of vertices adjaent,%m i is A(i) = 0 1 there is an edge from i to j}; the access0r set of i is S(i) = $1 there is a path of one or more edges from i to j).

An interval dag satisfies the following nestingprop- erty :

Suppose the nesting property has been verified for all vertices j > i. So the distinct successor sets S(j), j’> i, can be labelled as To 5 l .0 5 Tk_1 s Tk, where for convenience, Tk does not denote a successor& but rather Tk = {1, *.., n). Let Ts be the smallest set containing A(i). The nesting property implies T,_i s

Definition. A dag is an interval ‘&g iff for any two

vertices i, j, either S(i) c S(j) or S(j) E S(i).

So the distinct successor sets S(j) can be labelled as

* This research was supported in part by National Science Fouxidation Grant MCS 78-18909.

20

Fig. 1. Examplkgraph.

Page 2: A linear-time recognition algorithm for interval dags

Volume 12, number 1 INFORMATION PROCESSING LETTERS

S(i) 5 T,. So if T,_r 5 S(i) is false, the dag is not interval. Otherwise the dag seen so far is interval. If S(i) = Tg, the next vertex i - 1 can be processed. If S(i) lies properly between Tp_r and Tq' S(i) can be made a new T-set and then vertex i - 1 can be pro-

13 February 1981

(2)

(3) (4) (9

(6)

(7)

(8)

(9

letLbsTi,Tc,whereTr = {l,..., n),Te =@; let IN(i) point to T1 and SUCC(i) point to T,,,

for 1 <i<n;

cessed. To implement this approach efficiently, the fol-

lowing data structure is used (see Fig. 2). A set TJ is represented by a node t; it has a field

COUNT(t) = lTj I.

me nodes Tk, Tk_ f, . . . . To are linked, in this order, to form a linear list L. A vertex i has entries in two arrays:

SUCC(i) points to the node for set S(i); IN(i) points to the node for the smallest

set containing i.

Note the nesting property allows us to use COUNT fields to compare sets. Now we present the algorithm in pseudo+Sigol:

begin comment. This algorithm halts indicating whether or not the given dag is interval. If it is, a node t in L represents the successor set {i I IN(i) is t or is after t in L}, L gives the nesting order of successor sets, and vertex i has successor set SUCC(i);

initialization: (1) number the vertices in topological order;

I 2 3 4 5 6

IN

succ

-- J

Fig. 2. Data structure after vetiex 3 is processed.

.

processing: foricntolby-ldo

if A(i) # # then begin comment find _Ts, the smallest successor

set con@ining A(i), and TP, the largest successor set of some j E A(i);

let q point to the node that maximizes COUNT(IlU(j)) for j E A(i);

let p point to the node that maximizes COUNT(SUCC(j)) for j E A(i);

comment let LO = A(i) n Ts_r - TP, HI=A(i)nT, -Tp_r;

let LO = fi 1 j E A(i), COUNT(p) < COUNT(IN(j)) < COuMT(q));

let HI A fi I j E A(i), IN(j) = q}; comment find TP_r and check

Ts-r 5 S(i); let q’ point to the node following q in L; ifcoUNT(q’)>coUNT(p)+ ILOI

then halt (G is not interval); comment check ifs(i) = Ts; ifCOUNT = COUNT(q’) + MI1

then SUCC(i) + q else begin comment create a new successor

set for S(i); let t point to a new node between q and

q’, with COUNT(t) = COUNT(q’) + I HI I, SUCC(i) = t, and IN(j) = t for

jEHI; end end

halt (G is interval) end

Theorem. An interval dag can be recognized in time O(n tin).

Proof. Correctness of the algorithm followlv from the comments and the preceding discussion. Tiie linear time bound is obvious.

In an actual implementation, tne algorithm would be modified for greater speed. The topological num- bering could be eliminated by exploring the graph

21

Page 3: A linear-time recognition algorithm for interval dags

Volume 12, number 1 INFORMATION PROCESSING LETTERS 13 Febfilary 1981

depth-first, processing successors before predecessors. In line 6 it is more economical to compute only I LO I

convert the priority list to a schedule [§I. There seems to be no simple way to take advantage of-the special structure #of interv&diags to do Xhe conversion faster. and IHI i ; only in line 9 it might be necessary to reex-

amine A(i) to find HI. -

3. Application to scheduling

To implement the scheduling algorithm of Papadimitriou and Yannakakis, it is necessary to form a ‘priority list’ of the vertices i in decreasing order of IS(i)!. This is done by traversing L, listing all vertices i with SUCC(i) = t when node t is visited. It is easy to implement this in time O(n + m).

The complete scheduling algorithm runs in almost- linear time, O(no(n) + m) 5 Here, o(n) is the inverse of Ackermann’s firnction and is G3 for practical appli- cations [6]. The factor a(n) results from the time to

References

[1] E.G. Hoffman, Jr., Ed., Computer and Job-Shop S&d- uling Theory (Wiley, New York9 1976).

[ 2 ] T.C. Hu, Parallel sequen&g and assembly line problems, Operations Res. 9 (6) (1961) 841-&N

[3] D.E. Knuth, The Art of Computer Programming, Vol. 1 (Addison-Wesley, Reading, MA; 1968).

[4] C.H. Papadimitriou and M, Yan&akis, Scheduling interval-ordered tasks, SIAM 3. Comput. 8 (3) (1979) 405-409.

[S] R. Sethi, Scheduling graphs on two processors, SIAM J. Comput. 5 (1) (1976) 73-82.

[6] R.E. Tarjan, Efficiency of a good but not linear set union algorithm, J. ACM 22 (2) (1975) 215-225.

* This is slightly wars claimed in [4 1.

22