In: Computer Science
What is the greedy choice being made by Kruskal’s algorithm? Show that this choice results in an optimal substructure.
Definition of Greedy Algorithm:
Two conditions define the Greedy Paradigm:
Use of Greedy Approach:
Examples of Greedy Approach :
Now why greedy choice been made by kruskal's algorithm:
Introduction on kruskal's algorithm:
Kruskal’s algorithm uses the greedy approach for finding a minimum spanning tree.Kruskal’s algorithm treats every node as an independent tree and connects one with another only if it has the lowest cost compared to all other options available.
Important Point: To Know Why Kruskal's Algorithm is Greedy Approach:
The Krushkal's algorithm is a Greedy Algorithm. The Greedy Choice is to pick the smallest weight edge that does not cause a cycle in the MST constructed so far. |
Step to Kruskal’s algorithm:
Step 1: Sort the graph edges with respect to their weights.
Step 2: Start adding edges to the minimum spanning tree from the edge with the smallest weight until the edge of the largest weight.
Step 3: Only add edges which don’t form a cycle—edges which connect only disconnected components.
[OR]
In Simpler Form Explaination:
Step 1 – Remove all loops and parallel edges
Step 2 – Arrange all the edges in ascending order of cost
Step 3 – Add edges with least weight
Now, Why Greedy Algorithm is Optimal Substructure:
First let us know what is optimal substructure:
Optimal Substructure:
|