...

/

Minimum Spanning Tree

Minimum Spanning Tree

Find the minimum spanning tree of a connected undirected graph with weighted edges.

Statement

Find the minimum spanning tree (MST)MST of a connected, undirected graph with weighted edges.

Example

Consider the following graph:

g a 1 b 2 a->b 1 c 3 a->c 1 b->c 2 d 4 b->d 3 e 5 c->e 3 d->e 2

The minimum spanning tree of the above graph is:

g a 1 b 2 a->b 1 c 3 a->c 1 b->c 2 d 4 b->d  3 e 5 c->e 3 d->e 2

Sample input

Input will be a graph of the form:

v = 5
e = [ [ 1, 2, 1 ],
      [ 1, 3, 1 ],
      [ 2, 3, 2 ],
      [ 2, 4, 3 ],
      [ 3, 5, 3 ],
      [ 4, 5, 2 ] ]

where vv is the number of edges, and ee is the set of weighted edges. Each edge is coded as follows: [source,destination,weight] ...

Access this course and 1400+ top-rated courses and projects.