The two minimum spanning tree algorithms and the Dijkstra’s algorithm to find shortest part are examples of greedy algorithms.
a) Briefly describe what makes and algorithm a greedy algorithm. In other words, what are the characteristics of a greedy algorithm?
b) What greedy algorithm property Kruskal’s algorithm uses in finding the minimum spanning tree? Explain your answer
c) What greedy algorithm property Dijkstra’s algorithm uses in finding the shortest path? Explain your answer
a)
For algorithms with a large search space, one way to appoximate the optimal solution is to define a metric for estimating the “goodness” of a solution in a particular subspace. A greedy algorithm chooses the subspace to search in based on this approximation, then chooses the subspace of that subspace based on the same approximation metric, and so on until you get a solution. Greedy algorithms are usually fast, but their solutions are not always optimal, and you need to take care to define a good metric so that you get a near-optimal solution or get the optimal solution most of the time.
b)
Kruskal’s Algorithm builds the spanning tree by adding edges one by one into a growing spanning tree. Kruskal's algorithm follows greedy approach as in each iteration it finds an edge which has least weight and add it to the growing spanning tree.
Algorithm Steps:
c)
Djikstra used this property in the opposite direction i.e we overestimate the distance of each vertex from the starting vertex. Then we visit each node and its neighbours to find the shortest subpath to those neighbours.
The algorithm uses a greedy approach in the sense that we find the next best solution hoping that the end result is the best solution for the whole problem.
The two minimum spanning tree algorithms and the Dijkstra’s algorithm to find shortest part are examples...