Discrete Structures Lecture 12..
Discrete Structures Lecture 12..
Repeat:
they don’t form cycles, until the MST has 𝑛−1 edges (for a graph
Continue picking the smallest edges, adding them to the MST if
with 𝑛 nodes).
EXAMPLE OF KRUSKUL ALGORITHIM
KRUSKAL’S ALGORITHM PESUDO
The Correctness of Kruskal’s Algorithm
Assume the Algorithm is Wrong:
Suppose Kruskal's algorithm gives a wrong result, meaning it doesn't
produce an MST.
Adding a Wrong Edge:
If the algorithm adds a wrong edge, there must be a lighter edge
that should have been chosen instead.
Cut-and-Paste Argument:
If we split the graph into two parts, the smallest edge between them
must be in the MST. The algorithm always picks the smallest edge, so it
can’t pick a wrong one.
Contradiction:
Since the algorithm always picks the smallest edge, it cannot make a
wrong choice, proving it must produce the correct MST.
TIME COMPLEXITY:
Sorting the Edges:
1.Kruskal's algorithm starts by sorting all the edges based on
their weight.
2.Sorting takes O(E log E) time, where E is the number of edges.
3.Example: If there are 10 edges, sorting them based on weight
takes time proportional to 10 log 10.
Union-Find for Cycle Detection:
4.To avoid cycles and merge components, the Union-Find data
structure is used.
5.This step takes O(E log V) time, where V is the number of
vertices and E is the number of edges.
6.Example: For 10 edges and 5 vertices, checking and merging
takes time proportional to 10 log 5.
ADVANTAGES OF KRUSKAL'S
ALGORITHM
Efficient and Quick:
1.Works well for small and medium-sized networks.
2.Example: Designing road maps or cable connections.
Cost-Effective:
3.Ensures the lowest total cost for connecting points like
electricity cables or internet wires.
Straightforward:
4. Simple steps make it easy to understand and use in practical
scenarios.
5. Can efficiently combine separate Handles Disconnected Graphs:
6. networks.
7.Example: Connecting rural power grids.
DISADVANTAGES