Counting independent sets in graphs is known to be #P-complete in general , even for several restricted cases . Even approximate counting is NP-hard, and unlikely to be in polynomial time for bipartite graphs . However, smaller graph classes may permit polynomial time algorithms. For example,  gives a linear time algorithm for counting independent sets in bipartite permutation graphs. Here “linear time” means computable with a number of arithmetic operations and comparisons linear in the size of the graph. Similar results are known for chordal graphs  and tree-convex graphs . For information on these and other graph classes, see .
Counting cliques in a graph is equivalent to counting independent sets in the complementary graph. Thus, for general graphs, these two problems have equivalent complexity. However, for graph classes the two problems may have very different complexity.
Here we consider the problems of counting independent sets and cliques in three classes of graphs: cocomparability graphs, comparability graphs and permutation graphs. See section 2 below for definitions. In each case we show that either the counting problem can be accomplished in linear time, or else counting is #P-complete.
In section 3 we present a simple linear time algorithm for counting independent sets in cocomparability graphs, and show that counting cliques is #P-complete. We extend this to counting maximal independent sets, and independent sets of a given size, and maximal independent sets of a given size. In section 4, we modify this to give linear time algorithms for counting cliques in comparability graphs, and show that counting independent sets is #P-complete.
2 Preliminaries and notation
For integers and with the set of consecutive integers will be abbreviated as .
Let be a finite partial order, with . The cover relation of is its transitive reduction, defined by if and there is no with and . By we mean or .
A chain in is a set of pairwise comparable elements. That is, the restriction of to is a linear order. A chain with for all is tight if holds for all .
A linear extension of is a permutation of such that implies .
Let be a graph with vertex set , with and . Here all graphs are finite, undirected and simple, unless stated otherwise. We will denote the complementary graph by , where . Let , that is , and .
A clique in a graph is a set of pairwise adjacent vertices. A set of pairwise non-adjacent vertices is independent. Therefore a clique of is an independent set in the complement of and vice versa. A maximal clique or independent set is maximal with respect to set inclusion. By contrast, maximum refers to the largest cardinality.
A partial order can be considered as digraph with vertex set and arcs for all pairs such that . The comparability graph for is the underlying undirected graph of . That is, . Then a graph is a comparability graph if there is a partial order on the set such is the comparability graph of . Given a comparabity graph , a corresponding partial order and a linear extension can be computed in (linear) time . Note, however, that this algorithm does not certify that is a comparability graph. Recognition is currently only known in time. We will sidestep these issues by assuming the input comparability graph is given with a transitive orientation and a linear extension of this.
The complements of comparability graphs are called cocomparability graphs, so these are the incomparability graphs of partially ordered sets. Again, recognition is not known in linear time, but a linear time algorithm can compute and a linear extension for the complementary comparability graph [5, 10]. Again,
A graph is a permutation graph if there is a permutation of such that if and only if implies . It is not difficult to show that is a permutation graph if and only if it is both a comparability graph and a cocomparability graph. Permutation graphs can be recognised, and a permutation ordering obtained, in linear time , so we need no assumptions on the input graph.
These are well-established classes of graphs, and are all subclasses of perfect graphs. Important subclasses of comparability graphs are bipartite graphs and cographs. Interval graphs are an important subclass of cocomparability graphs (they are graphs that are both chordal and cocomparability). Permutation graphs are an important subclass of both comparability and cocomparability graphs.
3 Cocomparability graphs
Let be a cocomparability graph and let be a partial order on , with linear extension . We will extend the poset by a unique minimal element and a unique maximal element . That is, we define and for all , and (if not enforced by transitivity) . Let , for any . Then we denote the extended partial order by , If is linear extension of , and , we write for such that ,
Let be a cocomparability graph which is the incomparability graph of a poset , and let be the above extension. Then
a set is independent in if and only if is a chain of ;
a set is maximally independent in if and only if is a tight chain of .
Two vertices in are -comparable if and only if they non-adjacent in . The extra elements and are comparable to all vertices in . Together these imply property 1.
To see 2 we first consider an independent set of that is not maximal independent. Hence there is a vertex such that is still independent. By property 1 the set is a chain, and hence is also a chain, but not a tight one.
For every vertex let . Especially, and . Let . For every , the relation restricted to is a partial order with unique minimal element and unique maximal element .
3.1 Independent sets
For every vertex let be the set of independent sets of of with , and . That is, is the number of independent sets of . We can evaluate and recursively as follows:
The sets can be exponential in size (for example if ), but the recurrence for can be evaluated efficiently. We use the linear extension of to evaluate the equations above in the order , as shown. At the end is the number of independent sets in .
We show that the recurrence above is correct by proving a sequence of lemmas, which themselves are proven directly or by induction on .
For all every set is independent in and implies .
The base of the induction is for . Clearly is the unique independent set of .
Now let . Every set contains the vertex and vertices in for . By induction hypothesis is an independent set of some . Therefore only contains vertices of . Moreover is a chain in . By transitivity, and imply that is also a chain in and therefore an independent set of .
The latter argument also applies to . ∎
Every nonempty independent set of is contained in .
Let be an independent set of . This implies that is a chain of and therefore has a unique maximal element . We have and, by induction hypothesis, for some . Consequently we have , and clearly . ∎
For different we have .
If and are -incomparable then these are adjacent vertices of . Hence no independent set of can contain both and . By Lemma 2 for all and all we have and , that is, . Consequently holds.
Now let and be -comparable. By symmetry we may assume , especially . Again, Lemma 3 implies, for all and all , that holds. As before this means , and therefore . ∎
We can implement the above recurrences for directly, but it is clear that the time complexity is , not , since the summations are over the edges of . If , this clearly implies time, but otherwise we correct this as follows.
For all we define by
The values of and are mutually recursive:
The recurrence for is obvious, and for we have
as required. Now the summations are over the edges of , and the algorithm is time. Thus we have
Given a cocomparability graph on vertices, we can compute the number of its independent sets in time .
Lemmas 2 and 3 imply that, for all , the sets defined by the recurrence contains all independent sets of , especially is the set of all independent sets of . It remains to show that . To see this we observe that the unions over all are always disjoint by Lemma 4.
Our algorithm just recurrences for for all in the order of linear extension of . Then is the number of independent sets of . Assuming additions can be performed in constant time, this takes time, since each edge or non-edge of is used exactly once in the recurrences. ∎
The alternative evaluation of the recurrences which leads to can be used in all the algorithms below, and we will not elaborate further on this.
On the other hand, we have the following.
It is #P-complete to count cliques in a cocomparability graph.
In fact, even approximately counting cliques in cocomparability graphs appears to be hard, by the same argument, being equivalent to the canonical problem #BIS .
Finally, we note that counting independent sets in cocomparability graphs is equivalent to counting chains in partially ordered sets, and counting cliques is equivalent to counting antichains. See  and , where antichains are called downsets. Thus the results of this paper could be recast in the language of partial orders.
3.2 Maximal independent sets
Similarly we can compute the number of maximal independent sets. For every vertex let denote the set of maximal independent sets of with , and let . We can compute and as follows:
The only difference to and is that the partial order is replaced by its cover relation , as anticipated in Lemma 1. For all and all maximal independent sets of the set is maximal independent if and only if there is no that is -between and , hence if and only if .
The recurrence for and can be shown to be correct by arguments similar to the ones given above to justify the recurrence for and .
For all every set is a maximal independent set of and implies .
The base of the induction is for . Clearly is the unique independent set of .
Now let . Every set contains the vertex and vertices in for . By induction hypothesis is a maximal independent set of some . Therefore only contains vertices of . Moreover is a tight chain in . Since implies and because is transitive, and imply that is also a tight chain in and therefore a maximal independent set of .
A similar argument proves the assertion for . ∎
For every every maximal independent set of satisfies and implies .
Let be a maximal independent set of . By Lemma 1, is a tight chain of with minimal element and maximal element . Therefore implies . We show by induction. For we have . Otherwise, by induction hypothesis and the tightness stated above, for some . Consequently we have . ∎
Given a cocomparability graph on vertices, we can compute the number of its maximal independent sets in time.
It remains to show that . Again, the unions over all are always disjoint because holds for all , and by Lemma 4.
The time analysis is essentially the same as in the proof of Theorem 5. ∎
Corresponding to Theorem 6, we also have the following
It is #P-complete to count maximal cliques in a cocomparability graph.
3.3 Independent sets of size
Next we consider independent sets of size exactly for some fixed value of . For every vertex and every integer , the set of independent sets of with and , and size , satisfy the following recurrences:
The correctness of these recurrences is again based on the fact that, for every and every , every independent set of with and there is an independent set of of size for some , where if and otherwise is the -maximal vertex in . For we have because . Then we have the following.
For all and all every set is a independent set of with and .
For every every independent set of size is contained in .
Given a cocomparability graph on vertices and a number , we can compute the number of its independent sets of size exactly in time . In time we can do this for all .
Lemmas 2 and 3 imply that, for all , the sets defined by the recurrence contains indeed all independent sets of , especially is the set of all independent sets of . It remains to show that . To see this we observe that the unions over all are always disjoint by Lemma 4.
Our algorithm just evaluates the sums for for all in an order that is a linear extension of . Then is the number of independent sets of . Assuming additions can be performed in constant time, this takes time. ∎
As a by-product the algorithm of Theorem 13 computes the size of a maximum independent set of , which is , and the number of maximum independent set in , which is . Since every maximum independent set is also maximal, the algorithm from Theorem 17 can be used as well and should be faster on average.
Once the number of independent sets of size exactly has been determined for all we can evaluate the independent set polynomial for all values of .
We also have the following fixed-parameter hardness result for counting -cliques in cocomparability graphs.
It is #W-complete to count -cliques in a cocomparability graph.
3.4 Maximal independent sets of size
For every vertex and every integer , let be the set of maximal independent sets of with and , and . We have
The following are proved similarly to the correponding results above.
For all and all every set is a maximal independent set of with and .
For every and every maximal independent set of size in is contained in , and implies .
Given a cocomparability graph on vertices and a number , we can compute the number of its maximal independent sets of size exactly in time . In time we can do this for all .
We have no corresponding hardness result in this case, since the complexity of counting maximal -independent sets in bipartite graphs appears to be open.
4 Comparability graphs
Counting independent sets in a cocomparability graph is equivalent to counting cliques in its complement . Since our algorithms are symmetrical between and , all the results of section 3 remain true by interchanging the words “cocomparability” and “cocomparability”, and the words “clique” and “independent set”. Therefore, we will not detail the modified results.
5 Permutation graphs
Permutation graphs are both comparability and cocomparability graphs, so the algorithms of section 3 are valid both for counting independent sets in permutation graphs and (with obvious modifications) for counting cliques in permutation graphs. The result of  for counting independent sets in bipartite permutation graphs is a special case.
-  Andreas Brandstädt, Van Bang Le, and Jeremy P. Spinrad, Graph Classes: A Survey. SIAM Monographs on Discrete Mathematics and Application, Philadelphia (1999).
-  Derek G. Corneil, Stephan Olariu and Lorna Stewart, Asteroidal triple-free graphs. SIAM Journal on Discrete Mathematics 10 (1997), pp. 399-430.
-  Radu Curticapean, Holger Dell, Fedor V. Fomin, Leslie Ann Goldberg and John Lapinskas, A fixed-parameter perspective on #BIS, in Proc. 12th International Symposium on Parameterized and Exact Computation (IPEC 2017), Leibniz International Proceedings in Informatics (LIPIcs) 89 (2018), 13:1–13:13.
-  Martin Dyer, Leslie Ann Goldberg, Catherine Greenhill and Mark Jerrum, On the relative complexity of approximate counting problems, Algorithmica 38 (2003) 471–500.
-  Ekkehard Köhler and Lalla Mouatadid, Linear time LexDFS on cocomparability graphs, in: Algorithm Theory (SWAT 2014), Springer LNCS 8503 (2014) 319–330.
-  Dieter Kratsch, Ross Mcconnell, Kurt Mehlhorn and Jerry Spinrad, Certifying algorithms for recognizing interval graphs and permutation graphs, SIAM Journal on Computing 36 (2003), 326–353.
-  Min-Sheng Lin, Counting independent sets and maximal independent sets in some subclasses of bipartite graphs, Discrete Applied Mathematics, 2018.
-  Min-Sheng Lin and Chien-Min Chen, Counting independent sets in tree convex bipartite graphs. Discrete Applied Mathematics 218 (2017) 113–122.
-  Min-Sheng Lin and Chien-Min Chen, Linear-time algorithms for counting independent sets in bipartite permutation graphs. Information Processing Letters 122 (2017) 1–7.
-  Ross M. McConnell and Jeremy P. Spinrad, Linear-time modular decomposition and efficient transitive orientation of comparability graphs. Proceedings of the 5th Annual ACM-SIAM Symposium on Discrete Algorithms, (1994) 536–545.
-  Yoshio Okamoto, Takeaki Uno and Ryuhei Uehara, Counting the number of independent sets in chordal graphs. Journal of Discrete Algorithms 6 (2008) 229–242.
J. Scott Provan and Michael O. Ball, The complexity of counting cuts and of computing the probability that a graph is connected.SIAM Journal on Computing 12 (1983) 777–788.
-  Salil Vadhan, The complexity of counting in sparse, regular, and planar graphs, SIAM Journal on Computing 31 (2001), 398–427.