Use DFS but we cannot use visited [] to keep track of visited vertices since we need to explore all the paths. visited [] is used avoid going into cycles during iteration. (That is why we have a condition in this problem that graph does not contain cycle)

Start from the source vertex and make a recursive call to all it adjacent vertices.

During recursive call, if reach the destination vertex, increment the result (no of paths).

See the code for more understanding.

Code:

Output:

No of paths between source: 0 and destination: 5 are: 3

__________________________________________________ Top Companies Interview Questions..-

If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.
__________________________________________________