All the search queries that I see relate to the number of paths from the given node to another given node. But here is an algorithm that should find the total number of paths anywhere in the graph for any acyclic digraph. (If there are loops, there are an infinite number of paths unless you indicate that certain duplicate paths are excluded.)
Designate each node with the number of paths that end with node:
While not all nodes are labeled: Choose an unlabeled node with no unlabeled ancestors. (An implementation might here choose any node, and recursively process any unlabeled ancestors of that node first.) Label the node with one plus the sum of the labels on all ancestors. (If a node has no ancestors, its label is simply 1.)
Now just add tags on all nodes.
If you do not want to count paths of length zero, subtract the number of nodes.
aschepler
source share