Question

I have a class Node similar to Java's class Point with x and y coordinates, which I paint onto a JPanel. I'm trying to create a minimum spanning tree for a set of such nodes on a Euclidean graph, which I would then paint onto the panel as well. But I can't really figure out the data structure I'd need to do create the tree efficiently in the first place.

I've tried using LinkedLists and ArrayLists to implement Prim's algorithm, but they seem to make things overly complicated. What data structure should I be looking into for this instead?

Was it helpful?

Solution

Graph can be represented by adjacency list. I generally use Vector to create adjacency lists. They are very convenient to handle. Also use PriorityQueue to get minimum path cost.

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