I’d like to build a map algorithm and do the following thing:
First, create all points on the map.
Already given which points are connected and the length between them (as integers).
Now the problem is to find the shortest connection between them.
Therefore what I will do is to create an object of each point that contains a list of all the points this particular point is connected to and the length from the original point to that point.
An example would be:
From A to g there is a distance of 7
From A to c there is a distance of 3
Where A is connected to c and A is connected to g
My problem is that if I use HashMap I have some problems finding out whether or not the points are connected because HashMap is not easy to loop through is there an easier way to do this or is there an alternative to HashMap?
See Prim’s Algorithm and Dijkstra’s algorithm and Minimum Spanning Tree
If you have a set of vertices(a point in your case), and weights of the paths between them(distance in your case) its MST gives only the paths which connect all of the vertices and have the total sum of the distances minimum.
Prim’s Algorithm and Dijkstra’s Algorithm can be used to find the MST.