-1

I want to implement Krushkal's Algorithm in Java. This is not a question on how to implement Krushkal's since I want to try it myself before looking up the code. I have created a Node class and want to create a Graph class. The graph class contains a integer variable with the number of vertices(n), and one 2d array with edges(edges). The edges will be in this format [[u1,v1,w1],[u2,v2,w2]............[uk,vk,wk]] Here, u is first vertex v is 2nd vertex, w is weight of the edge

Now, I could create a edges 2d array with the number of rows set to n x (n-1)/2. This is the maximum number of possible edges. But, instead I want to use a data structure similar to a 2d Array, but the 2nd value is necessary, and the first is not. This way I can have 3 columns and unknown number of rows, which I can append when needed.

Now, I could create a edges 2d array with the number of rows set to n x (n-1)/2. This is the maximum number of possible edges. But, instead I want to use a data structure similar to a 2d Array, but the 2nd value is necessary, and the first is not. This way I can have 3 columns and unknown number of rows, which I can append when needed.

0 Answers0