-1

One of the requirement of Kruskal algorithm is to first initialize an empty set for the vertices but I'm having issues with it.

If i were to have a graph represented by

[1,2,4]
[10,3,5]
[6,1,3]

where the first index value is the source vertex, and the second value is the destination vertex and the third value is the weight, how would i initiate the empty set for the vertex?

I tried something like:

v_set = [0] * 11

but I'm limiting the vertex to only up to 11 hence if there was a vertex of 12 for example, it would produce an index out of range error. Would appreciate some help on this.

Maxxx
  • 3,688
  • 6
  • 28
  • 55

1 Answers1

0

You could represent your vertices as a list composed of the vertex numbers, and a list of edges, as tuples corresponding to the destination vertices and the weight of the edge:

Your graph could look something like this:

[1, [(2, 14), (3, 10)]]
[2, [(1, 14), (4, 2)]]
[3, [(1, 10)]]
[4, [(2, 2)]]

where:

       edge
      -----
[3, [(1, 10)]]
 ^    ^   ^ weight
 |    destination vertice   
 Vertice number
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80