Graph contains 'n' nodes and 'n-1' edges, hence, a unique path between any two nodes.
OK, so I know how we can find the vertices that lie on a path(given: source, destination) in a graph. It can easily be done by using DFS or BFS.
Example:
Input
List of entries, each entry contain Source and Destination vertices
Output
List of entries, each entry containing 'Vertices on path' corresponding to input entry.
Source Destination Vertices on path
5 4 5 4
3 5 3 4 5
1 3 1 5 4 3
3 5 3 4 5
5 4 5 4
My current solution
Currently I am running iterative DFS on each given path and finding the vertices that lie on that path.
Issue/Problem
When the no of nodes and no of paths given are large(~100,000) then finding the vertices on each given path(for all paths) is time consuming task.(Running DFS on each path for 100,000 paths for graph having 100,000 nodes). I want to know the better method of solving this problem. What data-structure or algorithm I may use instead of my current solution. Sometimes, I am also getting StackOverflow error, which I think is due to deep recursion.