0% found this document useful (0 votes)
7 views3 pages

Final Cheetsheet

Uploaded by

xdong2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Final Cheetsheet

Uploaded by

xdong2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Steps of Prim's Algorithm:

1. Initialize:
o Start with an arbitrary vertex as part of the MST.
o Maintain two sets:
 MST Set: Vertices included in the MST.
 Non-MST Set: Vertices not yet included.
o Keep a priority queue (or another data structure) to track the minimum edge connecting
MST and Non-MST sets.
2. Iterative Process:
o Select the edge with the smallest weight that connects a vertex in the MST set to a
vertex in the Non-MST set.
o Add this edge and the corresponding vertex to the MST set.
o Update the priority queue with edges originating from the newly added vertex.
3. Repeat until all vertices are included in the MST.
4. Result:
o The MST is complete when all vertices are in the MST set.
o The sum of the selected edge weights gives the total weight of the MST.

Steps of Kruskal's Algorithm:

1. Sort All Edges:


o List all the edges of the graph and sort them by weight in non-decreasing order.
2. Initialize Disjoint Sets:
o Use a Union-Find (or Disjoint Set Union, DSU) data structure to keep track of which
vertices are connected and detect cycles.
3. Iterate Through Edges:
o For each edge in the sorted edge list:
 Check if adding the edge forms a cycle (using the DSU to check if the endpoints
belong to the same set).
 If it does not form a cycle, include the edge in the MST.
 Stop when the MST has V−1V-1V−1 edges (where VVV is the number of vertices).
4. Output:
o The edges included in the MST form the result.
o The total weight of the MST is the sum of the weights of these edges.
To determine whether each collection of subsets is a partition of the given set AAA, recall the
conditions for a partition:

1. The subsets must be non-empty.


2. The subsets must be pairwise disjoint (no element belongs to more than one subset).
3. The union of all subsets must be equal to AAA (cover the entire set AAA).

You might also like