10
Minimum Spanning tree Prim’s algorithm 1. Select any vertex 2. Select the shortest edge connected to that vertex 3. Select the shortest edge which connects a previously chosen vertex to a new vertex 4. Repeat step 3 until all vertices have been connected

D1,L5 Prim's algorithm from a table.ppt

Embed Size (px)

Citation preview

  • Minimum Spanning treePrims algorithm

    Select any vertex

    Select the shortest edge connected to that vertex

    Select the shortest edge which connects a previously chosen vertex to a new vertex

    Repeat step 3 until all vertices have been connected

  • A cable company want to connect five villages to their network which currently extends to the market town of Avenford. What is the minimum length of cable needed?

    AvenfordFingleyBrinleighCornwellDonsterEdan2745864538Example

  • Prims algorithm in tabular formFirst put the information from the network into a distance matrix

    ABCDEFA-3--47B3-5--8C-5-4-6D--4-28E4--2-5F78685-

  • Start at vertex A. Label column A 1 . Delete row ASelect the smallest entry in column A (AB, length 3)1

    ABCDEFA-3--47B3-5--8C-5-4-6D--4-28E4--2-5F78685-

  • 1Label column B 2Delete row BSelect the smallest uncovered entry in either column A or column B (AE, length 4)2

    ABCDEFA-3--47B3-5--8C-5-4-6D--4-28E4--2-5F78685-

  • 12Label column E 3Delete row ESelect the smallest uncovered entry in either column A, B or E (ED, length 2)3

    ABCDEFA-3--47B3-5--8C-5-4-6D--4-28E4--2-5F78685-

  • 123Label column D 4Delete row DSelect the smallest uncovered entry in either column A, B, D or E (DC, length 4)4

    ABCDEFA-3--47B3-5--8C-5-4-6D--4-28E4--2-5F78685-

  • 123Label column C 5Delete row CSelect the smallest uncovered entry in either column A, B, D, E or C (EF, length 5)45

    ABCDEFA-3--47B3-5--8C-5-4-6D--4-28E4--2-5F78685-

  • 12345FINALLYLabel column F 6Delete row F6

    ABCDEFA-3--47B3-5--8C-5-4-6D--4-28E4--2-5F78685-

  • 12345FINALLYLabel column F 6Delete row F6The spanning tree is shown in the diagramLength 3 + 4 + 4 + 2 + 5 = 18Km

    ABCDEFA-3--47B3-5--8C-5-4-6D--4-28E4--2-5F78685-