...

/

Greedy Algorithms

Greedy Algorithms

Introduction to the concept of Greedy Algorithms.

Algorithm families

When we start solving a problem, we can do it in different ways. Not every way is optimal. Based on the problem, we have to decide which technique is best. Here are some of the techniques we’ll be learning in the upcoming lessons:
  • Greedy algorithm
  • Divide and conquer
  • Backtracking
  • Branch and bound
  • Dynamic programming

Greedy algorithms

Greedy algorithms, as the name suggests, take the greedy, or best, approach at any moment. The overall best solution is the combination of the smaller best solutions.

To make the correct choice, we should follow an objective function. Algorithm decisions are based on the value of the objective function at that time. Consider the example of minimizing cost. Our objective is to get the minimum value. We make the minimum value decision at each step, which will give us the minimum cost.

Properties of greedy algorithms

  • Easy to start with the solution.
  • Analyzing the run time of a greedy solution is easy.
  • Verifying the correctness is difficult.

    We can understand the greedy approach through the graph below. Our objective is to go from A to K with the minimum cost. When you travel from any edge, the overall cost increases with each step. You can only move forward. Let’s take a look with this graph.

  • The greedy approach will choose the best decision at any point. The movement from A>B ...