← Course home

Python reference · Reference

Greedy algorithms

Choose locally useful steps and examine when that choice leads to a global optimum.

ReferenceAbout 2 min

This page lists the library modules for Greedy algorithms. The lesson is Greedy methods.

This page is the module index for greedy algorithms.

  • greedy/classic.py — interval scheduling, fractional knapsack, Huffman codes.

Industry

A working engineer uses a min-heap when the greedy choice is the lightest remaining weight. Huffman coding in this module repeatedly takes the two lightest weights with heapq.heappop. Python documents a min-heap whose smallest item is heap[0], and heappop returns that item.

Implementation and tests Optional reference

Library code 1

  • bitsandbytes.greedy.classic

Use these references to compare the explanation with repository code and tests. A test link means it imports a lesson symbol; it does not by itself claim complete behavior coverage.