-1

Graph

Prim’s Algorithm

An algorithm for finding a minimum spanning tree.

  • Begin by choosing any edge with smallest weight, putting it into the spanning tree.
  • Successively add to the tree edges of minimum weight that are incident to a vertex already in the tree, never forming a simple circuit with those edges already in the tree.
  • Stop when n − 1 edges have been added.

I know that you must start at node A. Also by giving a list of the order in which nodes and/or edges are added.

But im not sure on the exact steps to find the minimum weight spanning tree.

beaker
  • 16,331
  • 3
  • 32
  • 49
la3anato
  • 1
  • 3
  • Why do you think you need to start at node A? That's not what the first step in the algorithm says, is it? – beaker May 05 '17 at 19:41
  • @beaker that's what i was told, when you use prims algorithm, you must start at node A, for this question at least. – la3anato May 06 '17 at 11:11
  • Then it's not Prim's algorithm. If you've been asked to do something else, then I suggest you talk to your TA and ask them if you're following their instructions correctly. – beaker May 07 '17 at 00:13

1 Answers1

0

Select all unvisited edges from A

A - B = 2

A - E = 2

A - F = 5

Find cheapest : A - B

Select all unvisited edges from A and B

A - E = 2

A - F = 5

B - C = 1

B - E = 2

B - F = 4

Find cheapest : B - C

Select all unvisited edges from A, B and C

A - E = 2

A - F = 5

B - E = 2

B - F = 4

C - D = 4

C - E = 1

Find cheapest : C - E

Select all unvisited edges from A, B, C and E

A - E = 2

A - F = 5

B - E = 2

B - F = 4

C - D = 4

E - D = 3

E - F = 1

Find cheapest : E - F

Node D is the only unvisited node, so it can either be; D -E OR C - D.

Cheapest = E - D : 3

Now all nodes have been visited, remove unused edges

Minimum weight spanning tree would look like this

la3anato
  • 1
  • 3