What is a creative way to display a family tree?

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

Was this solution helpful to you?

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

Find solution

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.