Dynamic Programming Algorithms on Directed Cographs

In this paper we consider directed cographs, which are defined by Bechet et al. by the disjoint union, series, and order composition, from an algorithmic point of view. Using their recursive structure we give dynamic programming algorithms to show that for every directed cograph the size of a largest edgeless subdigraph, the size of a largest subdigraph which is a tournament, the size of a largest semicomplete subdigraph, and the size of a largest complete subdigraph can be computed in linear time. Our main results show that the hamiltonian path, hamiltonian cycle, regular subdigraph, and directed cut problem are polynomial on directed cographs.


Introduction
Undirected cographs have been introduced in the 1970s by a number of authors under different notations, such as hereditary Dacey graphs (HD graphs) in [16], D * -graphs in [12], 2-parity graphs in [5], and complement reducible graphs (cographs) in [13]. Cographs can be characterized as the set of graphs without an induced path with four vertices [6]. From an algorithmic point of view the following definition is very useful. (a) Every single vertex is a cograph. (b) If G 1 , . . . , G k are cographs, then the disjoint union of the graphs G 1 , . . . , G k is a cograph. (c) If G 1 , . . . , G k are cographs, then the join of the graphs G 1 , . . . , G k is a cograph. By this definition every cograph can be represented by a tree structure, denoted as cotree. The leaves of the cotree represent the vertices of the graph and the inner nodes of the cotree correspond to the operations applied on the subexpressions defined by the subtrees. For every graph G one can decide in linear time, whether G is a cograph and in the case of a positive answer construct a cotree for G, see [7] or [11]. Using the cotree a lot of hard problems have been shown to be solvable in polynomial time when restricted to cographs. Such problems are clique, independent set, partition into independent sets (chromatic number), partition into cliques, hamiltonian cycle, isomorphism [6], and vertex disjoint paths [10]. On the other hand, the achromatic number problem is NP-complete for cographs [4].
Directed cographs were introduced in 1997 by Bechet et al. in [3] as follows. (a) Every single vertex is a directed cograph. (b) If G 1 , . . . , G k are directed cographs, then the disjoint union of the graphs G 1 , . . . , G k is a directed cograph. (c) If G 1 , . . . , G k are directed cographs, then the series composition of the graphs G 1 , . . . , G k is a directed cograph. (d) If G 1 , . . . , G k are directed cographs, then the order composition of the graphs G 1 , . . . , G k is a directed cograph. Also every directed cograph can be defined by a tree structure, denoted as di-cotree. The leaves of the di-cotree represent the vertices of the graph and the inner nodes of the di-cotree correspond to the 36 DYNAMIC PROGRAMMING ALGORITHMS ON DIRECTED COGRAPHS operations applied on the subexpressions defined by the subtrees. Also for every directed graph G one can decide in linear time, whether G is a directed cograph and in the case of a positive answer construct a di-cotree for G, see [8]. Directed cographs can be characterized by eight forbidden induced digraphs [8]. Calculus of directed cographs were also considered in connection with pomset logic in [14]. The algorithmic use of directed cographs has been shown in [2] using their decomposability into acyclic digraphs and semicomplete graphs and also by flow techniques (cf. Section 4.11.3 in [1]).
In this paper we use the recursive structure of directed cographs to give new dynamic programming solutions for the following problems. We show that for every directed cograph a largest edgeless subdigraph, a largest subdigraph which is a tournament, a largest semicomplete subdigraph, and a largest complete subdigraph can be computed in linear time. Further we show that the hamiltonian path, hamiltonian cycle, regular subdigraph, and directed cut problem are polynomial on directed cographs. For general digraphs all these problems are NP-hard.
Our approach can be applied to a lot of further digraph problems. The aim of this paper is not to complete the list of digraph problems which can be solved by dynamic programming on directed cographs, but to show that all these problems can be handled by dynamic programming solutions using the same scheme. We are also not interested in bounding the running time which is sometimes given by a polynomial of higher degree. Such considerations are only interesting if anybody really has to implement the solutions.

Digraphs
For some given digraph G = (V, E), we define its underlying undirected graph by ignoring the directions of the edges, i.e.

Directed Cographs
• The series composition of G 1 , . . . , G k , denoted by G 1 ⊗ . . . ⊗ G k , is defined by their disjoint union plus all possible arcs between vertices of G i and G j for • The order composition of G 1 , . . . , G k , denoted by G 1 ⊘ . . . ⊘ G k , is defined by their disjoint union plus all possible arcs between vertices of G i and G j for all 1 ≤ i < j ≤ k.
The class of directed cographs has been defined recursively in [3].
(ii) If G 1 , . . . , G k are directed cographs, then the disjoint union G 1 ⊕ . . . ⊕ G k is a directed cograph. † Thus we do not consider directed graphs with loops.
Obviously for every directed cograph we can define a tree structure, denoted as di-cotree. The leaves of the dicotree represent the vertices of the graph and the inner nodes of the di-cotree correspond to the operations applied on the subexpressions defined by the subtrees. For every directed cograph one can construct a di-cotree in linear time, see [8].
Since the disjoint union ⊕, the series composition ⊗, and the order composition ⊘ are associative, we can recursively transform every di-cotree T into a binary di-cotree T ′ for G.

Lemma 1
Every cotree T can be transformed into an equivalent binary di-cotree T ′ , such that every inner vertex in T ′ has exactly two sons. Table I shows the definition of a directed cograph and its di-cotree. Table I. Directed cograph expressions X 1 , . . . , X 5 , the defined digraphs, and a di-cotree for the directed cograph defined by expression X 5 .

Lemma 2
For every directed cograph its complement digraph is a directed cograph.

Proof
Let G be a directed cograph and X be a cograph expression for G. An expression c(X) for the complement graph co-G can recursively be defined as follows.
An obvious but important property of directed cographs is that they are hereditary, that is, every induced subdigraph of a directed cograph is a directed cograph. The proof follows, since an expression X ′ for an induced subdigraph G ′ can be obtained from an expression X of original graph G by restricting X to the vertices of G ′ .

Lemma 3
The set of directed cographs is hereditary.
Regarding the algorithmic use of special digraphs it is often helpful to know whether they are transitive or at least quasi transitive (cf. Section 6.7 in [1]). A digraph G is transitive if for every pair of arcs (x, y) and (y, z) with x ̸ = z the arc (x, z) also belongs to G. A digraph G is quasi transitive if for every pair of arcs (x, y) and (y, z) with x ̸ = z at least one of the arcs (x, z) and (z, x) also belongs to G. By the simple (X 1 ⊕ X 3 ) ⊗ X 2 expression, where X 1 consists of one vertex x, X 2 consists of one vertex y, and X 3 consists of one vertex z the following result follows.

Lemma 4
The set of directed cographs is not transitive and not quasi transitive.
In the next sections we give new and efficient algorithms for problems on directed cographs. By Lemma 1 and [8] we can assume that we are given our directed input cograph as a binary di-cotree. As an introductory example, we briefly consider the task of finding a subdigraph of special arc sets. (u, v) and (v, u) belong to E. The problems of finding a subdigraph of maximal size with one of these four properties P can be summarized as follows.

Independent Sets and Cliques
Let G be our directed input cograph defined by some expression X. Table II shows how we can recursively compute the size F (X) of a largest edgeless subdigraph (column 2), a largest subdigraph which is a tournament (column 3), a largest semicomplete subdigraph (column 4), and a largest complete subdigraph (column 5) in digraph defined by expression X from the subexpressions X 1 and X 2 . Operation + means that F (X) = F (X 1 ) + F (X 2 ) and operation max means that F (X) = max{F (X 1 ), F (X 2 )}.
Table II. The table shows the operations to compute size F (X) of a largest edgeless subdigraph, largest subdigraph which is a tournament, largest semicomplete subdigraph, and largest complete subdigraph in digraph defined by expression X from the subexpressions X 1 and X 2 .

Theorem 1
For every directed cograph on n vertices the size of a largest edgeless subdigraph, the size of a largest subdigraph which is a tournament, the size of a largest semicomplete subdigraph, and the size of a largest complete subdigraph can be computed in O(n) time.
Besides computing the sizes of the special vertex sets we additionally can compute a vertex set of this size following Table II. If the entry in the table is 1, we store the corresponding vertex. For + we store the union of the sets of the involved subexpressions. And for max we store the set of maximum size among the sets of the involved subexpressions. The correctness follows since on the one hand all computed vertex sets induce a subdigraph of the given property. On the other hand a larger set of the given property is not possible. In the case of + is this obvious by the size of the subdigraph and in the case of max the considered operation does not allow to choose vertices from both involved subdigraphs in order to fulfill the property, so it is best possible to choose the larger subdigraph.

Directed Cut
Name DIRECTED CUT Instance A directed graph G = (V, E) and a positive integer k. Question Is there a partition of V into V 1 and Let G = (V, E) be our directed input cograph defined by some binary expression X. Let F (X) to be the set of all such that x is the number of directed edges starting from vertices in V 1 and ending in vertices in V 2 . Then F (X) has at most (|V | + 1) · (|E| + 1) · (|V | + 1) ∈ O(|V | 2 · |E|) triples.
The following observations show that F (•) is computable in O(1) time, and F (X 1 ⊕ X 2 ), F (X 1 ⊗ X 2 ), and F (X 1 ⊘ X 2 ), are computable in polynomial time from F (X 1 ) and F (X 2 ).

F
Given a single vertex graph, we allow this vertex to be in V 1 or in V 2 of our partition.
For the disjoint union operation, we know the sizes of vertex sets in every partition V ′ 1 ∪ V ′′ 1 of the vertex set of the graph defined by X 1 and also the sizes of vertex sets in every partition V ′ 2 ∪ V ′′ 2 of the vertex set of the graph defined by X 2 . To realize the disjoint union, we store the size of the sets Since no additional edges are inserted, the number of edges is the sum of those of the two involved subdigraphs.
For the series operation, we perform the same combination of the sizes of the computed partitions. Since all possible edges are inserted in both directions, the number of relevant edges for the new partition V 1 ∪ V 2 is the sum of those of the two involved subdigraphs, i.e.
∈ F (X 2 )} For the order operation, we perform the same combination of the sizes of the computed partitions. Since only edges from V 1 to V 2 are inserted, the number of relevant edges for the new partition V 1 ∪ V 2 is the sum of those of the two involved subdigraphs, i.e.
There is a partition of the vertex set of directed cograph G into two disjoint sets V 1 , V 2 , such that there are at least r directed edges starting from vertices in V 1 and ending in vertices in V 2 , if and only if there is some triple (n 1 , x , n 2 ) ∈ F (X) such that x ≥ r.

Theorem 2
The directed cut problem for directed cographs on n vertices and m arcs is computable in O(n 2 · m) time.

Directed Hamiltonian Path and Hamiltonian Cycle
Name DIRECTED HAMILTONIAN PATH Instance A directed graph G = (V, E).

Question Is there a simple directed path on |V | vertices in G?
In order to solve the directed hamiltonian path and also the directed hamiltonian cycle problem on directed cographs one may consider the fact that directed cographs are totally decomposable into acyclic digraphs and semicomplete graphs (cf. Corollary 7.2 in [2]) and that for those digraphs both problems can be solved in polynomial time (cf. Section 6.7 in [1]). We next give different dynamic programming solutions.
Let G = (V, E) be our directed input cograph and X be a binary expression for G. For every partition of G into directed paths we want to store the number of these paths. To this end, for every subset E ′ ⊆ E such that the underlying undirected graph u(G ′ ) of subdigraph G ′ = (V, E ′ ) contains no cycles and every vertex in G ′ has indegree and outdegree at most 1, we define an integer n E ′ as follows. Integer n E ′ is the number of directed path v 1 , . . . , v r , r ≥ 1, in G ′ , where in-deg(v 1 ) = 0 and out-deg(v r ) = 0. Let F (X) be the set of all integers n E ′ for all such subsets E ′ ⊆ E. Since 1 ≤ n E ′ ≤ |V |, we know that F (X) has at most |V | integers.
Example 2 (F (X)) Let G = (V, E) be some digraph defined by some cograph expression X. Figure 1 shows two examples for subdigraphs G ′ = (V, E ′ ) such that the underlying undirected graph u(G ′ ) of G ′ contains no cycles and every vertex in G ′ has indegree and outdegree at most 1. These graphs lead the values 3 and 5 for n E ′ . That is,  The following observations show that F (•) is computable in O(1) time, and F (X 1 ⊕ X 2 ), F (X 1 ⊗ X 2 ), and F (X 1 ⊘ X 2 ), are computable in polynomial time from F (X 1 ) and F (X 2 ).
For the disjoint union operation, no additional edges are inserted and thus we add the number of paths of the graph defined by X 1 and the graph defined by X 2 .
3. F (X 1 ⊗ X 2 ) can be obtained as follows. Since we insert all new edges from the graph defined by X 1 to the graph defined by X 2 and all edges from the graph defined by X 2 to the graph defined by X 1 , we can glue a number of paths from X 1 and a number of paths from X 2 to one new path. Both numbers may differ at most by one. We start with the set of triples D = {0} × F (X 1 ) × F (X 2 ) and for every existing triple (n, n ′ , n ′′ ) ∈ D we insert into D the triples • (n + 1, n ′ − 1, n ′′ ) in order to pick one path of X 1 , • (n + 1, n ′ , n ′′ − 1) in order to pick one path of X 2 , • (n + 1, n ′ − x, n ′′ − x) in order to pick x ≤ n ′ paths from X 1 and x ≤ n ′′ paths from X 2 and glue them together by the edges inserted by the series operation, • (n + 1, n ′ − x, n ′′ − x − 1) in order to pick x ≤ n ′ paths from X 1 and x + 1 ≤ n ′′ paths from X 2 and glue them together by the edges inserted by the series operation, and • (n + 1, n ′ − x, n ′′ − x + 1) in order to pick x ≤ n ′ paths from X 1 and x − 1 ≤ n ′′ paths from X 2 and glue them together by the edges inserted by the series operation.
The last three operations are applied for all x meeting the stated conditions.
Then D gets at most (|V | + 1) 3 triples and thus is computable in polynomial time.
can be obtained as follows. Since we now only insert all new edges from the graph defined by X 1 to the graph defined by X 2 , we can glue one path from F (X 1 ) and one path from F (X 2 ) to one new path. We start with the set of triples D = {0} × F (X 1 ) × F (X 2 ) and for every existing triple (n, n ′ , n ′′ ) ∈ D we add into D the three triples • (n + 1, n ′ − 1, n ′′ ) in order to pick one path of X 1 , • (n + 1, n ′ , n ′′ − 1) in order to pick one path of X 2 , and • (n + 1, n ′ − 1, n ′′ − 1) in order to pick one path from X 1 and one path from X 2 and glue them together by one of the edges inserted by the order operation.
Then D gets at most (|V | + 1) 3 triples and thus is computable in polynomial time.
There is a directed hamiltonian path in digraph defined by expression X if and only if 1 ∈ F (X).

Theorem 3
The directed hamiltonian path problem for directed cographs is computable in polynomial time.
Question Is there a simple directed cycle on |V | vertices in G?
Let G be our directed input graph defined by some directed cograph expression X. Obviously G can only contain a directed hamiltonian cycle, if there are two cograph expressions X ′ and X ′′ , such that expression X is obtained by X = X ′ ⊗ X ′′ . In order to decide whether there is a directed hamiltonian cycle in digraph G we can apply the same data structure F (X) as for the hamiltonian path problem. There is a directed hamiltonian cycle in digraph defined by expression X if and only if there exists some integer x, such that x ∈ F (X ′ ) ∩ F (X ′′ ). By Theorem 3 we conclude the following result.

Theorem 4
The directed hamiltonian cycle problem for directed cographs is computable in polynomial time.

Regular Subdigraph
For d = 1 this problem is trivial since such a subdigraph exists unless G is acyclic. For d ≥ 2 the problem is NPcomplete [9]. The related problem of finding a spanning d-regular subdigraph (V, E ′ ) can be solved in polynomial time using an algorithm based on flows (cf. Section 4.11.3 in [1]). In order to give a dynamic programming approach, we next apply the recursive definition of a directed cograph.

DYNAMIC PROGRAMMING ALGORITHMS ON DIRECTED COGRAPHS
Let G = (V, E) be our directed input cograph defined by some cograph expression X. For a subdigraph G ′ = (V, E ′ ), E ′ ⊂ E, of G let M be the multiset such that for every vertex u of V , M has a pair (in-deg(u), out-deg(u)), where in-deg(u) and out-deg(u) is the indegree and outdegree, respectively, of u in the subdigraph G ′ . For some fixed integer d, let F (X) be the set of all mutually different multisets M for all subdigraphs of G in which all vertices have indegree at most d and outdegree at most d. Then F (X) has at most (|V | + 1) (d+1) 2 mutually different multisets each with at most |V | pairs (d 1 , d 2 ), where d 1 and d 2 are integers from 0 to d.
The following observations show that F (•) is computable in O(1) time, and F (X 1 ⊕ X 2 ), F (X 1 ⊗ X 2 ), and F (X 1 ⊘ X 2 ), are computable in polynomial time from F (X 1 ) and F (X 2 ).
For the disjoint union operation, no additional edges are inserted and thus we combine every subdigraph of the graph defined by X 1 and subdigraph of the graph defined by X 2 .
3. F (X 1 ⊗ X 2 ) can be obtained as follows. Since we insert all new edges from the graph defined by X 1 to the graph defined by X 2 and all edges from the graph defined by X 2 to the graph defined by X 1 , we can increase the indegree and outdegree of the vertices in graph defined by X 1 by the vertices in graph defined by X 2 , see (a), and increase the indegree and outdegree of the vertices in graph defined by X 2 by the vertices in graph defined by X 1 , see (b). It suffices to do this up to our bound of d. We start with set D = {⟨⟩} × F (X 1 ) × F (X 2 ) and insert into D all triples that can be obtained from some triple can be obtained as follows. Since we now only insert all new edges from the graph defined by X 1 to the graph defined by X 2 , we only can increase the outdegree of the vertices in graph defined by X 1 by the vertices in graph defined by X 2 , see (a), and increase the indegree of the vertices in graph defined by X 2 by the vertices in graph defined by X 1 , see (b). Again, it suffices to do this up to our bound of d. We start with set D = {⟨⟩} × F (X 1 ) × F (X 2 ) and insert in D all triples that can be obtained from some triple ( There is a d-regular subdigraph in the directed cograph defined by X if and only if there is some M ∈ F (X) such that for all (d 1 , d 2 ) ∈ M, d 1 = d 2 = d or d 1 = d 2 = 0 and there is at least one (d 1 , d 2 ) ∈ M with d 1 = d and d 2 = d. We conclude the following result.

Theorem 5
The d-regular subdigraph problem for directed cographs on n vertices is computable in O(n d 2 ) time.

Conclusions and Outlook
Since the algorithmic use of directed cographs seems to be nearly unexploited until now, we introduced new and efficient dynamic programming solutions for well known digraph problems using dynamic programming on directed cographs.
There are several interesting open questions. (a) For the non-linear time solutions: Can we find linear time algorithms for the problems on directed cographs? (b) On undirected cographs the hamiltonian cycle problem can be solved using the so called scattering number, see [12]. It would be interesting whether it is possible to define a similar number in order to decide the problem on directed graphs. (c) Are there any natural problems which can be solved in polynomial time on undirected cographs and its directed version becomes NP-hard on directed cographs? (d) Can we give a polynomial-time algorithm for the oriented vertex coloring (cf. [15] for a definition) problem on directed corecursively graphs?