Greedy Algorithms

Algorithms that make locally optimal choices at each step.

  • JSON3,777 B
  • YAML2,792 B · −26%
  • TOON2,412 B · −36%

Greedy algorithms and the problems they solve: activity selection, Huffman coding, Dijkstra, Kruskal, fractional knapsack and job sequencing, extended with Prim's and Boruvka's spanning-tree algorithms, canonical coin change, optimal merge patterns and greedy set-cover approximation.

Use it when

  • You need a canonical example of a greedy strategy.
  • You are checking whether a problem fits the greedy-choice property.

Watch out for

  • Greedy gives optimal answers only for problems with the greedy-choice property; the 0/1 knapsack and general coin change are counterexamples.
  • A greedy algorithm can still be a good approximation when it is not optimal, as for set cover.

The data

AlgorithmUse case
Activity SelectionSelect maximum compatible activities given start and end times.
Huffman CodingBuild optimal prefix-free binary encoding for symbols.
Dijkstra Shortest PathFind shortest paths from a source in graphs with non-negative weights.
Kruskal MSTBuild minimum spanning tree by adding cheapest edges.
Fractional KnapsackMaximize value when items can be broken into fractions.
Job SequencingSchedule jobs with deadlines to maximize profit.
Prim's MSTGrow a minimum spanning tree by repeatedly adding the cheapest edge that connects a new vertex.
Boruvka's MSTBuild a minimum spanning tree by adding the cheapest outgoing edge of every component in parallel rounds.
Coin Change (canonical systems)Make change with the fewest coins using the largest coin first; optimal only for canonical coin systems such as US coins.
Optimal Merge PatternMerge sorted files with minimum total cost by always merging the two smallest.
Greedy Set CoverApproximate the smallest collection of sets covering all elements by repeatedly picking the set that covers the most uncovered elements.

Fields

The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.

SectionFieldTypeExample
dataalgorithmstringActivity Selection
datause_casestringSelect maximum compatible activities given star…

Fetch the same bytes

The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.

curl "https://yjtoon.yunusemrevurgun.com/api/dataset/greedy-algorithms?format=toon"
const res = await fetch(
  "https://yjtoon.yunusemrevurgun.com/static-data/dataset/greedy-algorithms.toon"
);
const toon = await res.text();

Rate limit: 120 requests per minute per IP, no key and no signup. API reference →

Topics

  • algorithms
  • greedy
  • optimization

Search the library

Search by a topic, title, or keyword.

Start with a collection

Browse all 205 datasets