MCA 202: Discrete Structures Instructor Neelima Gupta [email protected] Table of Contents Primβs MST Algorithm Kruskal MST Algorithm Minimum Spanning Tree Minimum Spanning Tree ο Definition: Given a weighted undirected graph G=(V,E,W) , π: πΈ β β+ βͺ {0}, the spanning tree of that graph with total minimum weight is called a minimum spanning tree. THANKS Saumya Agarwal (Roll No 35) & Saurabh Garg(Roll No 36) (MCA 2012) Primβs Algorithm for Minimum Spanning Tree 1. Let π denote the vertices currently in the minimum spanning tree, start with any arbitrary vertex and include it in π. 2. Pick an edge (u,v) with minimum weight where u β π and v β π β π . 3. Include v in π. 4. Repeat steps 2-3 till π β π = {β } THANKS Saumya Agarwal (Roll No 35) & Saurabh Garg(Roll No 36) (MCA 2012) Example T Edges from T to V-T c Selected edge 8 6 b d 2 2 a 3 4 e f 2 5 3 7 h g THANKS Saumya Agarwal (Roll No 35) & Saurabh Garg(Roll No 36) (MCA 2012) Idea of Correctness β’ Let T be the set containing the vertices currently in the minimum spanning tree. Initially T= {β } β’ Claim: At any point of time, the partially constructed tree with π β π is a minimum spanning tree. β’ Exercise: Prove claim by induction. THANKS Saumya Agarwal (Roll No 35) & Saurabh Garg(Roll No 36) (MCA 2012) Cut β’ A cut is defined as a collection of edges which separates one collection of vertices from another. T V-T THANKS Saumya Agarwal (Roll No 35) & Saurabh Garg(Roll No 36) (MCA 2012) Kruskalβs algorithm Step 1: Sort the edges in the increasing order of weights. Step 2: Pick the minimum weighted edge and include it in your partial constructed forest if it does not form a cycle. Step 3: Repeat step 2 until you include all the vertices (n) or exactly (n-1) edges. Thanks: Shammi-37 and Shivangi-38 (MCA 202) Minimum Spanning Tree c Traversing edges: 6 8 be df b 4 1 3 d 3 e ah ef , de 2 f a fg cd , bc 5 2 7 h gh, ab g TheNow edge ο± we Similarly, βdeβ traversed βbcβ is traversed butthe included butwe not included. because it weights. forms cycle. ο±ο±The edge βabβ isisnot traversed atnot all as have included n-1 edges. ο± have completed tree, with minimized Thanks: Shammi-37 and Shivangi-38 (MCA 202) ο± How to check cycle: If both the vertices are of same component it will form cycle. ο± Data structure used: Linked list. How much time to check for cycles? How much time to merge two components? ο± Only constant amount of time is needed to perform step 2, as edges are already sorted before step 1. Thanks: Shammi-37 and Shivangi-38 (MCA 202)
© Copyright 2026 Paperzz