I am planing to make a metro route app which will display the shortest path between two given stations. So should i use tree and dijkstra's shortest path algorithm ? Is there any easier way?
-
-
Answer:
Since, you are dealing with distances only and they will only be positive, Dijkstra will work. Since, its a metro route app, and I hope the distances between the stations are not changing, you can pre-compute all the pair wise shortest path lengths and store it in memory and whenever a query is asked, you can return the answer. You can do the pre-computation as follows: For all the vertices (metro stations) in the map one by one, run Dijkstra's Algorithm, don't terminate the algorithm unless you have computed the shortest distance for all other stations from this station. This way, running Dijkstra N(the number of stations) times, you can compute the shortest distance matrix.
Pankaj Jindal at Quora Visit the source
Other answers
Since at any point of time you will use only 1 complete graph of all the stations and all the direct routes between each of them, I would suggest you use the *Floyd-Warshall* algorithm(http://en.m.wikipedia.org/wiki/Floyd%C3%A2%C2%80%C2%93Warshall_algorithm). To use Dijkstra's you will have to create a seperate graph between your 2 end-points each time the end points change.
Deepanshu Mehndiratta
Thanks for the A2A One answerer has already gotten it right. Floyd Warshall all pair shortest path algorithm is called so, because it gives the shortest path between every two nodes. Save thr result of the algorithm, poll this database when asked for the shortest distance.
Akheel Firoz
Related Q & A:
- How to make a dijkstra longest path?Best solution by stackoverflow.com
- How to make a native chat app in Swift?Best solution by udemy.com
- Could we use wifi in the philippines? i mean if u have a wifi enabled phone/laptop, will u be able to use it?Best solution by Yahoo! Answers
- How do i delete my old profile, but not my account or ID. I just want to make a new profile?Best solution by Yahoo! Answers
- What knot can I use to lash two objects together that will tighten on itself and not release?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.