Greedy Algorithms
This lesson introduces the greedy problem-solving technique.
We'll cover the following
Greedy method
Greedy is an algorithmic paradigm that builds up a solution, piece by piece. This means it chooses the next piece that offers the most obvious and immediate benefit. A Greedy algorithm, as the name implies, always makes the choice that seems to be the best at the time. It makes a locally-optimal choice in the hope that it will lead to a globally optimal solution.
If you have a problem where the locally-optimal choice leads to a global solution, the best fit is the Greedy technique.
The Greedy method can solve a problem that satisfies the below-mentioned properties:
- Greedy choice property: A global optimum can be arrived at by selecting a local optimum.
- Optimal substructure: An optimal solution to the complete problem contains an optimal solution to subproblems.
Greedy algorithms work by recursively constructing a set of pieces from the smallest possible constituent parts.
Example: find the largest path
Recursion is an approach to problem-solving in which the solution to a particular problem depends on solutions to smaller instances of the same problem.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.