![What Is Discrete (Decision) Maths](https://data.docslib.org/img/3a60ab92a6e30910dab9bd827208bcff-1.webp)
<p> Prim’s Algorithm</p><p>Prim’s algorithm also finds a minimum connector for a graph. The difference between Prim and Kruskal is that Prim’s algorithm builds up a connected graph, at each stage choosing the shortest edge to a new node from the existing graph. Like Kruskal’s, Prim‘s is also greedy.</p><p>The Algorithm</p><p>Step 1 Select a starting node</p><p>Step 2 Connect it to the NEAREST node i.e. the node that is joined to the starting node by the least weight. If there is more than one then it is a free choice.</p><p>Step 3 Connect the tree to the nearest vertex to the CONNECTED set. This is not necessarily from the node just connected. Again there may be a free choice.</p><p>Step 4 Repeat step 3 until all the nodes are connected.</p><p>Example Use Prim’s algorithm to find a minimum spanning tree for the following network and the value of that network.</p><p>LANG</p><p>£900 £600 £300 6th FORM £300 £200 OFFICE IT £400 £200 £300</p><p>LIBRARY</p><p>Choose 6th form as the starting point.</p><p>Nearest node is IT 6th FORM IT</p><p>Nearest is now either Library or Office so we have a free choice. </p><p>Choose Library 6th FORM IT</p><p>LIBRARY Nearest is now the Office from IT</p><p>OFFICE 6th FORM IT</p><p>LIBRARY</p><p>Nearest is now Languages from Office</p><p>LANGUAGES</p><p>OFFICE 6th FORM IT</p><p>LIBRARY</p><p>All the nodes are now connected so we have a minimum spanning tree. The value of this tree is £1000</p><p>Matrix Representation of Prim’s Algorithm</p><p>Whilst we may use Kruskal’s or Prim’s algorithm in other parts of D1 it is rare that a question will appear on the exam that is just to do with creating a minimum spanning tree. In exams you will be more likely to get a question in which you will be expected to apply Prim’s algorithm to a matrix. Again we follow an algorithm.</p><p>The Algorithm</p><p>Step 1 Choose a starting node. Delete the ROW corresponding to that node.</p><p>Step 2 Label the COLUMN corresponding to the starting vertex with a ‘1’ and ring the SMALLEST UNDELETED ENTRY in the column. If there is more than one entry that is the smallest then we have a free choice.</p><p>Step 3 Delete the ROW corresponding to the entry you have just ringed (this prevents you from revisiting any nodes).</p><p>Step 4 Label the COLUMN corresponding to the node you have just ringed ‘2’.</p><p>Step 5 Ring the SMALLEST UNDELETED ENTRY OUT OF ALL LABELLED COLUMNS (again there may be a choice).</p><p>Step 6 Repeat steps 3, 4 and 5 until all rows are deleted. Example Using the previous example but this time in matrix form.</p><p>Languages 6 Form IT Library Office Languages 900 600 300 6 Form 900 300 400 IT 600 300 200 200 Library 400 200 300 Office 300 200 300</p><p>Start at languages. Label the Languages column 1 and cross out the Languages row.</p><p>1 Languages 6 Form IT Library Office Languages 900 600 300 6 Form 900 300 400 IT 600 300 200 200 Library 400 200 300 Office 300 200 300</p><p>Smallest uncovered value in the Languages column is 300, which corresponds to the office. Circle this value; label the Office column ‘2’ and then cross out the Office row.</p><p>1 2 Languages 6 Form IT Library Office Languages 900 600 300 6 Form 900 300 400 IT 600 300 200 200 Library 400 200 300 Office 300 200 300</p><p>Smallest uncovered value in EITHER the Languages column or Office column is 200, which corresponds to IT. Circle this value, label the IT column 3 and cross out the IT row.</p><p>1 3 2 Languages 6 Form IT Library Office Languages 900 600 300 6 Form 900 300 400 IT 600 300 200 200 Library 400 200 300 Office 300 200 300</p><p>Smallest uncovered value in EITHER the Languages, Office or IT columns is 200, which corresponds to Library. Circle this value, label the Library column 4 and cross out the Library row. 1 3 4 2 Languages 6 Form IT Library Office Languages 900 600 300 6 Form 900 300 400 IT 600 300 200 200 Library 400 200 300 Office 300 200 300</p><p>Smallest uncovered value in EITHER the Languages, Office IT or Library columns is 300, which corresponds to 6th Form. Circle this value, label the 6th Form column 5 and cross out the 6th Form row.</p><p>1 5 3 4 2 Languages 6 Form IT Library Office Languages 900 600 300 6 Form 900 300 400 IT 600 300 200 200 Library 400 200 300 Office 300 200 300</p><p>All rows are now deleted and the circled numbers gives us both the way the minimum spanning tree is connected (i.e. IT to 6th Form and IT to Library etc) as well as the value. From this we can draw the minimum spanning tree.</p><p>Languages</p><p>Office</p><p>6th Form IT</p><p>Library</p><p>Value = 300 + 300 + 200 + 200 = 1000</p><p>Example Write down the matrix that represents the following network. Apply Prim’s algorithm to this matrix to find the minimum spanning tree and its value. </p><p>B 8 A 3 E 4 5 1 6 D 7 C Solution starting at A</p><p>1 5 4 2 3 A B C D E A 8 5 B 8 4 3 C 4 7 1 D 5 7 6 E 3 1 6</p><p>Minimum spanning tree is AD, DE, EB, EC with total weight 5 + 6 + 3 + 1 = 15</p><p>Get them to experiment to see what happens when a different node is selected as the starting node.</p><p>P35 Ex 3A Questions 2c, 3 & 5 P39 Ex 3B P45 Miscellaneous Ex Question 1, 2, 3, 5, 7 & 8 Worksheet</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages5 Page
-
File Size-