greedy-algorithms

Certify greedy strategies with exchange argument proofs and optimal substructure.

7|Updated Apr 24, 2026
One-click install
npx skills add https://github.com/Arcadi4/nerdy --skill greedy-algorithms
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: greedy-algorithms
Source: https://github.com/Arcadi4/nerdy/tree/main/clrs
Command: npx skills add https://github.com/Arcadi4/nerdy --skill greedy-algorithms

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Greedy algorithms provide a disciplined framework for obtaining fast, often optimal, solutions by making locally optimal choices and proving safety.

Core Features & Use Cases

  • Provides a proven skeleton for greedy correctness through exchange arguments and safety proofs.
  • Helps decide when to favor greedy strategies versus dynamic programming or other methods.
  • Covers classic problems such as Activity Selection, Fractional Knapsack, Huffman Coding, and Offline Caching.

Quick Start

Validate a proposed greedy rule by identifying the greedy choice, showing the residual subproblem remains of the same form, and proving safety with an exchange argument.

Frequently Asked Questions about greedy-algorithms

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prove a greedy algorithm is correct using an exchange argument?

To prove a greedy algorithm is correct, identify the greedy choice, show the residual subproblem retains the same structure, and demonstrate safety by swapping an optimal solution's choice with the greedy choice without degrading the overall result.

When should I use a greedy algorithm instead of dynamic programming?

Use a greedy algorithm instead of dynamic programming when locally optimal choices guarantee global optimality, verifiable via exchange arguments and optimal substructure. Dynamic programming is preferred when overlapping subproblems exist without a provably safe greedy choice.

What is the greedy approach for activity selection and fractional knapsack problems?

The greedy approach for activity selection picks the earliest finishing interval to maximize count, while fractional knapsack selects items by highest value-to-weight ratio. Both require exchange arguments to prove the locally optimal choice yields a globally optimal solution.

How do I write a proof skeleton for Huffman coding greedy correctness?

Write a proof skeleton for Huffman coding by establishing optimal substructure, then apply an exchange argument demonstrating that merging the two lowest-frequency nodes is a safe choice that exists within some optimal prefix code tree.

Why does my greedy algorithm produce a suboptimal solution for offline caching?

A greedy algorithm produces a suboptimal solution for offline caching when the local eviction rule lacks safety. You must verify the greedy decision via an exchange argument to ensure the local choice matches the optimal global strategy.