Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 1

Lupsan Sabrina

Group 1025

Is Kruskal a Greedy Algorithm?


(yes it is)

Greedy is an algorithm that is fast, has a low complexity, but usually gives an acceptable
solution, and not always the optimal one. It does exactly what its name says – it is greedy. At every
step, the chosen path is the optimal path of that step but it doesn't always lead to the best overall
solution. It is used when the optimal solution is not worth spending many resources on better
algorithms. The algorithm I chose is Kruskal, because this Greedy algorithm always results in the
optimal solution.
The common characteristics of the Greedy procedure are that the input is a set with a limited
number of elements, the solution is a subset of the initial set and the final solution is not unique. In
Kruskal, the given set is the set of edges of the graph, the solution is a subset containing only the
necessary edges (so that the graph is a spanning tree, meaning that every vertex is connected with
the rest and there are no cycles) and the final solution is not the only possible one. In fact, there can
be multiple optimal solutions if, for example, in a cycle, two of the edges have the same value,
Greedy algorithm simply choosing one of them and rejecting the other one. Therefor, Kruskal is a
Greedy procedure, matching the common characteristics that allow applying it.
We can identify the general elements of the Greedy algorithm in Kruskal: every element in
the given set has a value, which is the cost. So every edge has a cost, Greedy always choosing the
edge that has the smallest value – starting with the beginning.
Initially, the input set is sorted in ascending order (Kruskal-specific), so that the first element
of the solution is the edge that has the smallest cost, and the solution subset is empty. Then, at every
iteration, the next edge with the smallest value that was not placed in the solution subset already is
placed, but with one condition – if it doesn't form a cycle. After maximum n iterations, the resulting
solution is a subset that represents the edges of a minimum spanning tree. As it is a Greedy
algorithm, the final solution is not unique, but it is always optimal, because, in Kruskal, we do not
have to follow a path but only choose from the ascending ordered set of edges.
In conclusion, Kruskal's algorithm is a Greedy one because, at every step, it chooses the best
edge, always checking if it is acceptable and adding it to the constructed solution if it is, resulting in
a solution that represents a minimum spanning tree. Also, the same algorithm can be applied if we
want to find a spanning tree that has the highest total of the edges' value, changing a few conditions
and sorting the initial set in a descending order.

You might also like