nrOfPaths

fun nrOfPaths(startNode: T, targetNode: T, mod: Long = Long.MAX_VALUE): Long

Calculates the number of distinct paths from the starting node to the target node in the graph.

This function assumes that the graph is a Directed Acyclic Graph (DAG) and uses dynamic programming to count the number of paths efficiently.

Return

The number of distinct paths from the starting node to the target node.

Parameters

startNode

The starting node.

targetNode

The target node.

mod

Makes the function return the nrOfPaths modulo mod. Defaults to Long.MAX_VALUE

Throws

IllegalStateException

If either the starting node or the target node is not found in the graph.