Skip to the workspace
Pebellslearn by building
Hard Problems & Adversarial Search  ›  Lesson

Reductions

Reductions 32 minTwo hard problems can be the same problem in disguise: a set S is independent exactly when everyone else is a vertex cover

dsa / Reductions

Explore each scene at your own pace.

01 · Two conflicting bidders can't both win

Two conflicting bidders can't both win

Reductions

Definition
A reduction transforms instances of one problem into instances of another so that solving the second solves the first; it shows the first is no harder than the second, as with independent sets and vertex covers, which are complements of each other.
In plain words
If you can translate a question into another question you already know how to answer, you have solved the first. Bidders who never conflict form one group, and everyone else forms the other, so finding one hands you the other.

In short: a reduction shows that two problems are secretly the same problem. If you can turn any instance of problem A into an instance of problem B, solve B, and turn B's answer back into an answer for A, then A is "no harder than" B — and if the reverse translation also exists, they're exactly as hard as each other. This lesson builds one concretely: a group of bidders with no conflicts between them (an independent set) and the group left over once you remove it (a vertex cover) are the same object seen from two directions. Solve either search and the other answer falls out for free, with nothing left to compute.

A chain of four bidders acme-bolt-crane-delta; acme and crane circled green as the independent set, bolt and delta circled red as the vertex cover, with a complement arrow looping between the two boxes

Two conflicting bidders can't both win

Meridian's bid desk is handed a tender where some bidder pairs can't both be awarded — maybe they'd need the same depot slot at the same hour. Draw a node per bidder and an edge per conflict:

watch it move · graph

Four bidders, three conflicts. Which group can all be awarded together, and which group has to be turned away to clear every conflict?

Try acme and crane together. The edges acme-bolt and bolt-crane don't connect two chosen nodes, and crane-delta doesn't either — no conflict lands inside this group. It's independent. 4 nodes, 3 edges, undirected. Settled: acme, crane.

1 / 2

An independent set and a vertex cover of the same graph are complements of each other — every bidder is in exactly one of the two groups:

What does this print?
def is_independent_set(bidders, conflicts, group):
    group_set = set(group)
    return all(not (a in group_set and b in group_set) for a, b in conflicts)

def is_vertex_cover(bidders, conflicts, cover):
    cover_set = set(cover)
    return all(a in cover_set or b in cover_set for a, b in conflicts)

bidders = ["acme", "bolt", "crane", "delta"]
conflicts = [("acme", "bolt"), ("bolt", "crane"), ("crane", "delta")]
group = ["acme", "crane"]
cover = [b for b in bidders if b not in group]
print(is_independent_set(bidders, conflicts, group), is_vertex_cover(bidders, conflicts, cover))
Scene 1 of 5
Project context and further resources
You're building a piece ofMeridian — the bid desk
This piece — smallest_conflict_resolution(): Two ways of reading the same bidder-conflict graph: the largest group that can all be awarded together, and the smallest group that has to be excluded. Solving one hands you the other for free.
Scenario Some bidder pairs on Meridian's tender can't both be awarded the same route slot. The bid desk wants the largest group it can award with no conflicts, AND the smallest group it has to turn away to make every conflict go away — and it turns out solving either one hands you the other for free.
smallest_conflict_resolution.py
Call the function you wrote — just like your app's frontend would. Edit the inputs and hit Call.
smallest_conflict_resolution(bidders, conflicts) → dictThe largest group of bidders with no conflicts between them, and the smallest group left over that has to be excluded.
try:
returned
Press Run to execute your code.
Press Check to run the tests for this lesson.
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.