What is the good data structure for railway routes. I have information about all the trains, what all stations they are passing through. Given two stations, I need to come up with all possible paths.
I came up with a graph where key is the start station and an adjacency list represents the stations it is passing through.
But I think this will not give me correct answer .
Sounds like a straight-forward graph problem, and (to me) modelling the way the railwork network actually looks with the graph sounds intuitive.
That is, have a graph node for each station, with edges representing railway connections between them.
The problem then becomes a graph search, for which there are plenty of algorithms to choose from.