Greedy_Algorithm_Introduction
Greedy_Algorithm_Introduction
Introduction
Understanding the fundamentals of
the Greedy Algorithm
Your Name | Date | Institution
What is a Greedy Algorithm?
• - A greedy algorithm makes the best possible
choice at each step.
• - It does not reconsider previous choices.
• - Used when a local choice leads to a global
optimum.
• - Example: Coin Change Problem.
Characteristics of Greedy
Algorithms
• - Greedy Choice Property: Locally optimal
leads to globally optimal.
• - Optimal Substructure: Optimal solutions to
subproblems.
• - Non-revisiting Property: Decisions are final.
• - Examples: Prim’s, Kruskal’s, Huffman Coding.
Steps in a Greedy Algorithm
• 1. Identify optimal substructure.
• 2. Define objective function.
• 3. Make greedy choices.
• 4. Check correctness.
• 5. Derive final solution.
Advantages & Disadvantages
• Advantages:
• - Fast execution.
• - Simple implementation.
• - Works well for optimization problems.
• Disadvantages:
• - May not always be optimal.
• - Fails when future choices matter.
• - Not suitable for all problems.
Examples of Greedy Algorithms
• 1. Activity Selection Problem
• 2. Huffman Encoding
• 3. Dijkstra’s Algorithm
• 4. Fractional Knapsack Problem
When to Use a Greedy Algorithm?
• - Works for problems with optimal
substructure & greedy choice property.
• - Best for:
• - Graph algorithms (Prim’s, Kruskal’s,
Dijkstra’s)
• - Scheduling problems
• - Resource allocation
• - Not suitable for backtracking problems.
Conclusion & Summary
• - Greedy algorithms make locally optimal
choices.
• - Suitable for problems with optimal
substructure.
• - Common in graph problems, scheduling, and
optimization.
• - Not all problems can be solved optimally
using a greedy approach.