Question

I have a question about Java algorithm of one program. I want to write an android program that provides information about "bus route". Program is worked that user selects one bus station(A station) and program says to user "take the bus number 4,and take off B station.And take the bus number 8 then take off C station." Anyone has an idea about that programs algorithm? What can I use for saving each bus route? Queue, stack or someting like that? Can I use BFS or DFS algorithm for shortest bus route path?

Purpose of program; How can user finds the transportation route with using Bus. (Bus number 4 does not go to the station 8 directly,user needs transfer to station B)

I need to know ; Which data structure and which shortest path algorithm do I use.

Thats a question

Was it helpful?

Solution

Implementation for Dijkstra's Algorithm in Java

The place in code where the vertex are initialized, you initialize all your bus routes.

In place where adjacency matrix is defined, for each of your stop initialize with stops where buses are available. Now run the algorithm. You might keep additional info along each edge such as possible bus numbers.

OTHER TIPS

Assuming you're working Java in the background and you'd go for Dijkstra algorithm, you basically need to get and manage a graph instance. Maybe there are even graph libraries/implementations which would already got DFS and BFS algorithms and so Dijkstra or Kruskal.

I'd suggest creating a graph implementation based on a Java HashTable. Having each node as Key and the adjacency list as Value per each.

Using ArrayList's, Stack's Queue or PriorityQueue might help.

You'd maybe have to implement a simple Node class and get static methods for doing Dijsktra, DFS, Kruskal, BFS, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top