Search code examples
algorithmgraphtopological-sort

Is there any-way to count the total number of topological sort in a DAG without finding the all possible order?


Suppose this is a question.....

enter image description here

How can I calculate total number of the topological sort without finding all orders?


Solution

  • In general this is #P-complete. This particular graph happens to be series–parallel, however, which makes it easy. Graphs in series cause the number of possibilities for each graph to be multiplied. For the particular graph you show, there are three diamonds in series, each of which has two valid extensions, so there are eight possibilities.