Presentation is loading. Please wait.

Presentation is loading. Please wait.

MCA 202: Discrete Structures Instructor Neelima Gupta

Similar presentations


Presentation on theme: "MCA 202: Discrete Structures Instructor Neelima Gupta"— Presentation transcript:

1 MCA 202: Discrete Structures Instructor Neelima Gupta ngupta@cs.du.ac.in

2 Table of Contents Prim’s MST Algorithm Kruskal MST Algorithm

3 Minimum Spanning Tree

4 THANKS Saumya Agarwal (Roll No 35) & Saurabh Garg(Roll No 36) (MCA 2012)

5 Prim’s Algorithm for Minimum Spanning Tree THANKS Saumya Agarwal (Roll No 35) & Saurabh Garg(Roll No 36) (MCA 2012)

6 Example a b c d ef h g 2 8 6 2 4 3 7 5 2 3 THANKS Saumya Agarwal (Roll No 35) & Saurabh Garg(Roll No 36) (MCA 2012) T Edges from T to V-T Selected edge

7 Idea of Correctness THANKS Saumya Agarwal (Roll No 35) & Saurabh Garg(Roll No 36) (MCA 2012)

8 Cut A cut is defined as a collection of edges which separates one collection of vertices from another. THANKS Saumya Agarwal (Roll No 35) & Saurabh Garg(Roll No 36) (MCA 2012) T V-T

9 Thanks: Shammi-37 and Shivangi-38 (MCA 202) 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. Kruskal’s algorithm

10 Thanks: Shammi-37 and Shivangi-38 (MCA 202) a b c d h e g f 2 4 2 6 1 3 8 3 7 5 Minimum Spanning Tree Traversing edges: be df ah ef, de  The edge ‘de’ is traversed but not included because it forms cycle. fg cd, bc  Similarly, ‘bc’ is traversed but not included. gh, ab  The edge ‘ab’ is not traversed at all as we have included n-1 edges. a b c h e g f  Now we have completed the tree, with minimized weights. d

11 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.


Download ppt "MCA 202: Discrete Structures Instructor Neelima Gupta"

Similar presentations


Ads by Google