0% found this document useful (0 votes)
64 views22 pages

Kruskal's Algorithm

The document discusses Kruskal's algorithm for finding minimum spanning trees. It defines greedy algorithms, minimum spanning trees, and compares Kruskal's algorithm to Prim's algorithm. It then provides steps to generate a minimum spanning tree using Kruskal's algorithm and works through an example graph.

Uploaded by

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

Kruskal's Algorithm

The document discusses Kruskal's algorithm for finding minimum spanning trees. It defines greedy algorithms, minimum spanning trees, and compares Kruskal's algorithm to Prim's algorithm. It then provides steps to generate a minimum spanning tree using Kruskal's algorithm and works through an example graph.

Uploaded by

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

Kruskal’s Algorithm

Group 4
Ron Andrei Fontanilla

Searching Algorithm:
Kehn Adolf Valle
Marvin Jose Hibid
Emelito Lavapie
Table of contents:

Greedy Algorithm

Advantages and Disadvantages of a Greedy Algorithm

Introduction to Kruskal’s Algorithm

What is a Minimum Spanning Tree

Differences of application between Kruskal & Prim Algorithms

Creating a Minimum Spanning Tree using Kruskal


What is a “Greedy
Algorithm”?
A greedy algorithm is an approach for
solving a problem by selecting the best
option available at the moment. It doesn't
worry whether the current best result will
bring the overall optimal result.

The algorithm never reverses the earlier


decision even if the choice is wrong. It works
in a top-down approach.

This algorithm may not produce the best


result for all the problems. It's because it
always goes for the local best choice to
produce the global best result.
Advantages:
Simplicity: Greedy algorithms are usually straightforward to understand and implement. They
follow a step-by-step approach where the best possible decision is made at each stage based
on the current information. This simplicity makes them easier to design and analyze compared
to more complex algorithms.

Efficiency: Greedy algorithms often have low time complexity and can run efficiently even for
large input sizes. The greedy approach typically involves making local optimal choices, which
can lead to faster execution times compared to exhaustive search or dynamic programming
techniques.

Memory efficiency: Greedy algorithms often require minimal memory usage. They usually
don't need to store the entire problem space or maintain an extensive set of intermediate
solutions. Instead, they only need to store the current best solution and update it as they
progress.
Disadvantages:
Lack of global optimization: Greedy algorithms make locally optimal choices at each step
without considering the overall solution. As a result, they may not always lead to the globally
optimal solution. The greedy approach may overlook future consequences and make choices
that seem optimal at the moment but turn out to be suboptimal in the long run.

Lack of backtracking: Greedy algorithms do not backtrack or reconsider decisions made


earlier. Once a choice is made, it is not revisited, even if better options become available
later. This can lead to suboptimal solutions or even incorrect results.

Dependency on problem structure: Greedy algorithms heavily rely on the problem's


structure and the specific criteria used to make greedy choices. Different problem structures
may require different criteria for selecting the next step, and the same greedy algorithm may
not work well for all problem instances.
Introduction to Kruskal’s Algorithm
• Kruskal’s algorithm is the concept that is introduced in the graph theory of
discrete mathematics. It is used to discover the shortest path between two
points in a connected weighted graph.
• The Kruskal algorithm is used to generate a minimum spanning tree for a
given graph.
• Kruskal’s algorithm sorts all the edges in increasing order of their edge
weights and keeps adding nodes to the tree only if the chosen edge does
not form any cycle.
• Also, it picks the edge with a minimum cost at first and the edge with a
maximum cost at last. Hence, you can say that the Kruskal algorithm
makes a locally optimal choice, intending to find the global optimal
solution. That is why it is called a Greedy Algorithm.
What is a Minimum Spanning Tree?
A minimum spanning tree (MST) is a subset
of the edges of a connected, edge-weighted
graph that connects all the vertices together
without any cycles and with the minimum
possible total edge weight. It is a way of
finding the most economical way to connect
a set of vertices. A minimum spanning tree is
not necessarily unique. All the weights of the
edges in the MST must be distinct. If all the
weights of the edges in the graph are the
same, then any spanning tree of the graph is
an MST. The edges of the minimum
spanning tree can be found using the greedy
algorithm or the more sophisticated Kruskal
or Prim's algorithm.
What is the difference between Kruskal and Prim
Algorithms?

Kruskal
Prim

Prim - It starts to build the Minimum Spanning Tree from any vertex in the graph and
traverses one node more than one time to get the minimum distance.

Kruskal - It starts to build the Minimum Spanning Tree from the vertex carrying minimum
weight in the graph and traverses one node only once.
Prim
Kruskal
Creating a Minimum Spanning Tree
Using Kruskal’s Algorithm
You will first look into the steps involved in Kruskal’s Algorithm to generate a minimum spanning
tree:

Step 1: Sort all edges in increasing order of their edge weights.

Step 2: Pick the smallest edge.

Step 3: Check if the new edge creates a cycle or loop in a spanning tree.

Step 4: If it doesn’t form the cycle, then include that edge in MST. Otherwise, discard it.

Step 5: Repeat from step 2 until it includes |V| - 1 edges in MST.

Using the steps mentioned above, you will generate a minimum spanning tree structure. So,
now have a look at an example to understand this process better.
The Graph
The graph G(V, E) given below contains 6 vertices and 12 edges. And
you will create a minimum spanning tree T(V’, E’) for G(V, E) such that
the number of vertices in T will be 6 and edges will be 5 (6-1)
Removing Elements from the Graph
If you observe this graph, you’ll find two looping edges connecting the same
node to itself again. And you know that the tree structure can never include a
loop or parallel edge. Hence, primarily you will need to remove these edges
from the graph structure.
Creating a Sorted list - Step 1
Source Vertex & Graph Edges Edge Weight & Destination Vertex
E F2
F D2
B C3
C F3
C D4
B F5
B D6
A B7
A C8

The next step that you will proceed with is arranging all edges in a sorted list by their edge weights.

After this step, you will include edges in the MST such that the included edge would not form a cycle in your
tree structure.
Picking the Smallest Edge - Step 2
The first edge that you will pick is edge EF, as it has a
minimum edge weight that is 2.
Continuation - Step 2

Add edge FD to the spanning


tree.
Checking if the New Edge generates a Loop - Step
3

Add edge BC and edge CF to the spanning tree


as it does not generate any loop.
Discarding Edges that generates loops -
Step 4

Next up is edge CD. This edge


generates the loop in Your tree
structure. Thus, you will discard this
edge.
Continuation - Step 4

Following edge CD, you have edge


BF. This edge also creates the loop;
hence you will discard it.
Continuation - Step 4

Next up is edge BD. This edge


also formulates a loop, so you will
discard it as well.
Final Step and the Completed MST using Kruskal -
Step 5

Next on your sorted list is edge AB. This edge


does not generate any cycle, so you need not
include it in the MST structure. By including this
node, it will include 5 edges in the MST, so you
don’t have to traverse any further in the sorted
list. The final structure of your MST is
represented in the image.

The summation of all the edge weights in MST


T(V’, E’) is equal to 17, which is the least
possible edge weight for any possible spanning
tree structure for this particular graph.
THANK YOU

Thank You

You might also like