This sounds like a classic case of the A * algorithm, but if you cannot implement Dijkstra, I donβt see you insert A *.
A * on Wikipedia
edit: this suggests that you have a good way to estimate (but it is imperative that you not overestimate) the cost of getting from one node to the target.
edit2: you are having trouble presenting an adjacency list. It occurs to me that if you create an object for each vertex on the map, you can directly link these objects when there is a link. So, you have essentially a list of objects, each of which contains a list of pointers (or links, if you like) to the nodes to which they are adjacent. Now, if you want to access the path for the new node, you just follow the links. Be sure to keep a list of the paths that you followed for this vertex to avoid endless loops.
As for database queries, every time you need to get something, you still have to do it. Your best hope is to only query the database when you DON'T ... it means only querying when you want to get information about a particular edge in the graph or for all edges for one vertex on the graph (the latter is likely to be the best route), so from time to time you choose slow I / O, rather than giant pieces at once.
source share