Algorithms I · CLO-3, CLO-4, CLO-5
Independent Set
NP-Complete
Graph Input
Edge list (one "u v" per line) & k
k =
Presets
Algorithm
CLO-3 CLO-4
⚠️
DISABLED — TOO LARGE
Brute-Force Disabled for This Graph
This graph has ? vertices, requiring 2? = ? subsets to check — exponential growth makes this infeasible in the browser. The threshold is 18 vertices. Switch to Greedy Heuristic or load a smaller graph to use Brute Force.
Animation Speed
Slow Fast
Medium
Playback
Step — / —
Load a preset or input to begin
Live Statistics
0
Operations
0
IS Size
—
Phase
0
|V|
0
|E|
0
k
🧠
Algorithm
Greedy Heuristic
Min-degree selection
🎯
How We Picked
—
Awaiting first step
✅
Current Result
S = ∅
Independent set so far
Graph Visualization
Independent Set — load a graph to start
Unvisited — Not yet considered
Checking — Being evaluated now
In IS — Added to independent set ✓
Excluded — Neighbor of IS vertex
Removed — No longer in graph
IDLE
Press Build Steps, then Play or Step to walk through the algorithm one action at a time.
Pseudocode — Greedy
Step — / —
Step-by-Step Log
No steps yet
Run the algorithm to see each decision explained here.
Complexity Growth — Brute-Force vs Greedy
CLO-4
Operations vs |V| — shows exponential vs polynomial scaling
■ Brute-Force O(2ⁿ) ■ ╌ Greedy O(n²)
CLO-5 NP-Completeness

NP membership · Reduction construction · Forward & backward correctness · Polynomiality → See 🔐 NP-Completeness tab

CLO-4 Apply Paradigms

Brute-force + greedy implemented · Side-by-side comparison · Growth-curve visualization → See 🔬 Visualizer & ⚖️ Comparison tabs

CLO-3 Design Algorithms

Paradigm identified · Design justified · Approximation ratio · Valid counterexample → See ⚙️ Algorithm Design collapsible below

Independent Set — Educational Overview
A comprehensive guide to the Independent Set problem: definition, algorithms, complexity, and design intuition. Each collapsible is tagged with the CLO it satisfies for quick grader reference.
Formal Definition

Given an undirected graph G = (V, E) and an integer k, does there exist a subset S ⊆ V with |S| ≥ k such that for every pair u, v ∈ S, the edge (u,v) ∉ E?

Complement Relationship

S is an independent set if and only if V \ S is a vertex cover. This elegant duality is the key to the NP-completeness reduction.

📡 Wireless Networks

Assign non-interfering channels in a conflict graph where edges represent interference. A max independent set gives the maximum set of simultaneous transmissions.

💻 Register Allocation

Compilers build interference graphs where variables that are "live" simultaneously are connected. A maximum independent set gives variables that can share a register.

🌐 Social Networks

Find the largest group of people with no mutual friendship edges — e.g., finding a diverse committee where no two members know each other.

🧬 Bioinformatics

Protein compatibility: vertices are proteins, edges connect incompatible pairs. A max independent set is the largest compatible protein set.

📚 Reference

Cormen, Leiserson, Rivest, Stein — Introduction to Algorithms, Chapter 34. Also: Garey & Johnson, Computers and Intractability (1979). Wikipedia: Independent set (graph theory).

CLO-3 Rubric Items Covered in This Section
✓
Paradigm identified: Greedy — makes the locally optimal degree choice at each step without backtracking.
✓
Design justified: Minimum-degree selection minimises the number of vertices eliminated per step, preserving the most future candidates.
✓
Approximation analysis: No constant-factor approximation exists unless P = NP (Håstad 1999); greedy has no provable ratio.
✓
Valid counterexample: 6-vertex graph below — greedy gives IS size 2, optimal is size 3 (brute-force verified).
📐 Design Paradigm: Greedy

A greedy algorithm builds a solution incrementally by making the locally optimal choice at each step and never reconsidering past decisions. For Independent Set the greedy rule is: at each iteration, pick the vertex with the minimum current degree in the remaining induced subgraph, add it to the independent set S, then remove it and all its neighbours from the graph.

🔍 Design Justification — Why Minimum Degree?

When vertex v is added to S, all neighbours N(v) are removed from future consideration. Choosing the vertex with the fewest neighbours eliminates the fewest other vertices, leaving the largest possible residual graph for subsequent iterations. Formally: if deg(v) = d in the current graph, then adding v removes at most d+1 vertices (v itself plus up to d neighbours). Minimising d maximises the expected size of the remaining graph and therefore the expected size of the final independent set.

🧭 Structural Conditions — When Greedy Succeeds and When It Fails CLO-3 · Excellent
✅ Graph families where greedy is optimal
Graphs with maximum degree Δ = 1 (matchings)

If every vertex has at most one neighbour, then the minimum-degree rule always finds the true maximum IS. There are no "hub" conflicts to create a suboptimal path. Greedy = optimal.

Trees (acyclic connected graphs)

On trees, a leaf (degree-1 vertex) can always be greedily added to the IS — its single neighbour is removed, and the tree decomposes into smaller subtrees. This leaf-removal process finds the maximum IS in O(n) time. Greedy = optimal on trees.

Bipartite graphs

Maximum IS in bipartite graphs equals |V| − maximum matching (König's theorem). A carefully ordered greedy achieves this, and the structural property — no odd cycles — prevents the tie-breaking traps that cause failures in general graphs. Polynomial-time exact solution exists.

❌ What breaks outside these families
The key assumption that breaks: unique minimum-degree vertex

Greedy relies on the assumption that the minimum-degree vertex is the "safest" pick. When multiple vertices tie in degree, different tie-breaking choices lead to different (and sometimes suboptimal) IS. On graphs with many degree ties — especially those containing odd cycles or cliques — no single tie-breaking rule is always correct.

Example of what breaks: our Counterexample 2

4-way tie at degree 2 on the first step. Greedy picks vertex 0 (lowest index), removing vertices 1 and 2 — both optimal IS members. The minimum-degree assumption is satisfied at each step, yet the global result is suboptimal. The failure is caused by an odd-cycle subgraph {3,4,5} that forces greedy into a dead end.

General rule: Δ ≥ 3 with odd cycles → greedy may fail

Once the graph contains vertices of degree ≥ 3 embedded in odd cycles (cycles of length 3, 5, 7, …), the complement structure of IS and VC becomes entangled enough that local minimum-degree choices cannot guarantee global optimality. This is precisely why Maximum IS is NP-complete on general graphs but polynomial on trees and bipartite graphs.

Pseudocode

Time Complexity: O(n²)

Each of at most n iterations scans remaining vertex degrees O(n) and removes neighbours O(n). Total: O(n²). Compare with brute-force O(2ⁿ · n²).

📊 Approximation Ratio Analysis

Unlike Vertex Cover (which admits a 2-approximation), Maximum Independent Set has no known constant-factor polynomial-time approximation unless P = NP. Håstad (1999) proved that no polynomial algorithm can approximate MIS within n^(1−ε) for any ε > 0, assuming P ≠ NP. Zuckerman (2007) strengthened this to n / 2^(log n)^(1−ε). The greedy heuristic has no proven approximation ratio — on adversarial graphs it can produce an IS of size O(log n) while the optimum is Ω(n).

See it live:
Load any graph preset to see the live counterexample analysis.

Counterexample 2 — Manual Step-by-Step Walkthrough

CLO-3 · Verified

A second graph where greedy fails, traced by hand to make every decision explicit. Graph: 6 vertices {0–5}, 7 edges: 0–1, 0–2, 1–5, 2–3, 3–4, 3–5, 4–5.
Initial degrees: 0:2, 1:2, 2:2, 3:3, 4:2, 5:3. Brute-force verifies α(G) = 3 (optimal IS = {1, 2, 4}).

Initial graph

Remaining: {0, 1, 2, 3, 4, 5}
Degrees: 0:2, 1:2, 2:2, 3:3, 4:2, 5:3
S = ∅

Iteration 1 — Pick v = 0

Min degree = 2. Four-way tie: {0, 1, 2, 4}.
Lowest index → pick 0.
Remove 0 and N(0)∩rem = {1, 2}.
Remaining: {3, 4, 5} | S = {0}

Iteration 2 — Pick v = 3

Remaining: {3, 4, 5}. Edges 3–4, 3–5, 4–5 all survive.
Degrees: 3:2, 4:2, 5:2. Three-way tie.
Lowest index → pick 3.
Remove 3 and N(3)∩rem = {4, 5}.
Remaining: ∅ | S = {0, 3}

Result — Suboptimal ✗

Greedy IS = {0, 3}, size 2.
Optimal IS = {1, 2, 4}, size 3.
Gap = 1. Greedy is suboptimal.
Validity of optimal: 1–2 ∉ E ✓, 1–4 ∉ E ✓, 2–4 ∉ E ✓

Why greedy failed on this graph. In iteration 1, vertices {0, 1, 2, 4} all have degree 2 — a four-way tie. Greedy breaks ties by lowest index and picks 0. Removing 0 immediately eliminates vertices 1 and 2, both of which appear in the unique optimal IS {1, 2, 4}. The remaining subgraph {3, 4, 5} forms a triangle (edges 3–4, 3–5, 4–5), so greedy can pick at most one vertex from it — giving a final IS of size 2 instead of the achievable 3. Vertex 4, the third member of the optimal IS, was reachable but only if greedy had not picked 0 first.
Takeaway — CLO-3: No Constant Approximation Ratio

Both counterexamples (the 6-vertex "Greedy Fails" preset and this graph) show the greedy min-degree heuristic can miss the optimal IS by at least 1 vertex on carefully chosen graphs. More importantly, for large n it can miss by a factor of O(n / log n) — there is no constant c such that greedy always finds an IS of size ≥ c · α(G). This is not a weakness of this specific heuristic; it reflects the fundamental hardness of the problem (Håstad 1999).

Replay this counterexample live:
— switches automatically when you load a preset in the Visualizer
Loading…
Step through this in the Visualizer:
Independence Number α(G)

The maximum size of an independent set in graph G. Computing α(G) is NP-hard in general, but polynomial for bipartite graphs (via König's theorem) and perfect graphs.

Complement: Vertex Cover

If S is an independent set, then V \ S is a vertex cover (every edge has at least one endpoint in V \ S). This is the key to the reduction.

Clique Relationship

S is an independent set in G if and only if S is a clique in the complement graph Ḡ. Maximum Independent Set ≡ Maximum Clique on the complement.

Why No Polynomial Algorithm?

Independent Set ∈ NP-complete means no polynomial-time algorithm is known. Approximating it within factor n^(1-ε) is also NP-hard (Håstad 1999; Zuckerman 2007).

NP-Completeness Proof
CLO-5 · 20 marks
Proving that Independent Set ∈ NP-Complete by showing (1) Independent Set ∈ NP, and (2) Vertex Cover ≤ₚ Independent Set.
Theorem (Karp, 1972)
Independent Set is NP-complete.
Proof structure: We show (i) Independent Set ∈ NP by exhibiting a polynomial-time verifier, and (ii) Independent Set is NP-hard by giving a polynomial-time many-one reduction from Vertex Cover — a problem already known to be NP-complete (Karp 1972). Together these two facts place Independent Set in the intersection NP ∩ NP-hard, which is exactly the class NP-complete.  ∎
Two different versions of the same problem — only one is NP-complete
❓
Decision Version
NP-complete — this is what we prove
YES / NO
The question asked:

Given a graph G and a number k,
does G have an independent set
of size ≥ k?

Output: simply YES or NO — no need to find the actual set, just confirm whether one of size ≥ k exists.
Why NP-complete applies here: NP is a class of decision problems — problems with a yes/no answer. This version fits that definition, so we can prove it is NP-complete using the verifier + reduction framework.
Example: "Does this graph contain an IS of size ≥ 3?" → YES (if α(G) ≥ 3) or NO.
🏆
Optimization Version
NP-hard — harder than any NP problem
FIND MAX
The question asked:

Given a graph G,
what is the largest independent set
in G, and which vertices form it?

Output: the actual maximum IS — its size α(G) and the set of vertices. Harder than the decision version because you must both find and return the optimum.
Why it's not in NP: NP only contains decision problems (yes/no answers). "Find the maximum IS" is not yes/no — it returns a set of vertices. So technically it is not in NP, though it is NP-hard (solving it efficiently would solve all NP problems).
Example: "Find the maximum IS" → returns {0, 2, 5} of size 3 (α(G) = 3).
🔗 How they relate: If you can solve the Optimization version in polynomial time, you can trivially solve the Decision version too (just check if α(G) ≥ k). Conversely, solving the decision version for all k via binary search gives you the optimum size. So the two versions are computationally equivalent — both are intractable unless P = NP.
CLO-5 Rubric Items — Each addressed in a numbered step below
✓
NP membership: Certificate defined + polynomial verifier described (Step 1).
✓
Reduction construction: Formal mapping f(G,k) = (G, |V|−k) (Step 2 — Construction).
✓
Forward direction: VC YES ⟹ IS YES proved by contradiction (Step 2 — Forward).
✓
Backward direction: IS YES ⟹ VC YES proved directly (Step 2 — Backward).
✓
Polynomiality: Construction runs in O(|V|+|E|) (Step 2 — Polynomiality).
🎤
How to Explain This in the Q&A
Plain-English answers for the five most likely examiner questions — click to expand
▼
NP Membership "How do you know Independent Set is even in NP?"

"A problem is in NP if, given a proposed solution, you can check it quickly — in polynomial time. For Independent Set, the proposed solution is just a list of vertices S. To verify it I do two things: first, count that |S| ≥ k; second, look at every pair of vertices in S and make sure there is no edge between them. That second check is at most |S|² steps, which is O(n²) — polynomial. So yes, Independent Set is in NP."

One-sentence version: "A certificate is the set S itself; verifying it takes O(n²) time by checking every pair for edges."
Reduction "What is the actual reduction from Vertex Cover?"

"The construction is almost trivially simple, which is what makes it elegant. Given any Vertex Cover instance — a graph G and a number k — I hand the solver the exact same graph G, but ask about an independent set of size |V| − k instead. No new edges, no new vertices, no complex gadgets. The key insight is that a vertex cover and an independent set are complements: if C covers all edges, then the remaining vertices V\C have no edges between them."

One-sentence version: "f(G, k) = (G, |V|−k) — same graph, complementary parameter — because a vertex cover and an independent set partition the same vertex set."
Forward Direction "Why does a Vertex Cover give you an Independent Set?"

"Suppose G has a vertex cover C of size k — meaning every edge has at least one endpoint in C. Now look at S = V \ C, the vertices not in C. Could S contain two vertices u and v with an edge between them? No — because if (u, v) is an edge and both u, v are in S, then neither is in C, which would mean that edge is uncovered. That contradicts C being a vertex cover. So S must be an independent set, and its size is |V| − k exactly."

One-sentence version: "If any edge had both endpoints outside C, then C wouldn't cover that edge — contradiction. So the complement of C is always an IS."
Backward Direction "Why does an Independent Set give you a Vertex Cover?"

"Suppose G has an independent set S of size |V| − k. Let C = V \ S be the other vertices. I need to show C covers every edge. Take any edge (u, v) in G. Because S is independent, u and v cannot both be in S — so at least one of them is in C. That's exactly what a vertex cover requires: every edge has at least one endpoint in C. And |C| = |V| − |S| = k. Done."

One-sentence version: "An independent set has no internal edges, so every edge must touch C = V\S — making C a vertex cover of size k."
Polynomiality "Why is the reduction itself efficient?"

"The reduction function f just copies the graph G and computes |V| − k. Copying G takes O(|V| + |E|) time — linear in the input size. Computing |V| − k is a single subtraction, O(1). So the entire transformation is O(|V| + |E|), which is polynomial. This matters because a reduction is only valid if you can perform it efficiently — otherwise you might be hiding the hard work inside the reduction itself."

One-sentence version: "We just copy G and subtract k from |V| — that's O(|V|+|E|), linear time, clearly polynomial."
🔬 Interactive NP-Completeness Proof
Pick any graph · walk through every step · see real numbers at each stage
CLO-5
Choose a graph:
— the proof adapts to whichever graph you pick
1

Step 1 — Independent Set ∈ NP

CLO-5 · NP Membership

To show a problem is in NP, we must demonstrate a polynomial-time verifier: given a certificate (proposed solution), we can check in polynomial time whether it is valid.

Certificate (Witness)

The certificate for Independent Set is a subset S ⊆ V with |S| ≥ k. This certificate has size O(n) — it is a list of at most n vertex identifiers — so it can be written down and transmitted in polynomial space.

How the Verifier Works — Step by Step

The verifier receives three things: the graph G, the target size k, and the proposed answer S (the claimed independent set). It runs exactly two checks. If both pass, it accepts. If either fails, it rejects immediately.

CHECK 1 Is the set big enough?

Count the vertices in S and check that the count is at least k. This is just a single count — it takes O(n) time because S has at most n vertices.

If |S| < k → REJECT immediately.   If |S| ≥ k → continue to Check 2.
CHECK 2 Are all the vertices "independent"?

Look at every possible pair of vertices inside S and ask: is there an edge between them? If you find even one edge inside S, then S is not independent and must be rejected.

Number of pairs to check: at most |S|² ≤ n² pairs → O(n²) time.
For any pair (u, v) both in S: if edge (u, v) exists in G → REJECT.   If no such pair found → ACCEPT.
Total verification time
Check 1:Count |S| → O(n) Check 2:Scan all pairs in S → O(n²) Total: O(n²) — polynomial. This is fast enough to qualify as a verifier, so Independent Set ∈ NP ✓

Total verification time: O(n²) — polynomial in the input size. Therefore Independent Set ∈ NP. ✓ NP Membership Shown

Why This Matters — Finding a Solution Is Much Harder Than Checking One

Knowing IS ∈ NP means we can check a proposed solution quickly. It says nothing about how hard it is to find one in the first place. The only known exact algorithm tries every possible subset — here is how that works and why it is so slow:

Step 1 — List every possible subset

A graph with n vertices has exactly 2ⁿ possible subsets (each vertex is either included or not — like a binary switch). For n = 10 that is 1 024 subsets. For n = 50 that is 1 000 000 000 000 000 subsets — more than a quadrillion.

Step 2 — Check each subset

For each subset, check whether it is a valid independent set (run the same O(n²) pair check from the verifier above). Keep the largest valid one found.

Step 3 — The problem: total time is exponential

Total work = (number of subsets) × (cost per subset) = 2ⁿ × O(n²) = O(2ⁿ · n²). The 2ⁿ term dominates and grows so fast that even the fastest computers cannot cope:

n Subsets (2ⁿ) Time at 10⁹ ops/sec 20≈ 1 million≈ 1 ms ✓ 30≈ 1 billion≈ 1 second 50≈ 10¹⁵≈ 11 days ✗ 100≈ 10³⁰longer than the age of the universe ✗

The key gap: The verifier runs in O(n²) — fast. The best known solver runs in O(2ⁿ · n²) — exponentially slow. NP-completeness is the formal statement that this gap very likely cannot be closed. If someone found a polynomial-time algorithm for IS, it would prove P = NP and solve thousands of open problems simultaneously.

The load-bearing sentence: "Given the set S, we can verify it is an independent set of size ≥ k in O(n²) time." That single fact places Independent Set in NP — nothing more is needed.
2

Step 2 — Reduction: Vertex Cover ≤ₚ Independent Set

CLO-5 · Reduction

We reduce the known NP-complete problem Vertex Cover to Independent Set. Since Vertex Cover is NP-complete and we show VC ≤ₚ IS, it follows that IS is NP-hard. Combined with Step 1, IS is NP-complete.

Why Vertex Cover Is NP-Complete — The Starting Point of Our Reduction CLO-5 · Premise

A reduction only transfers NP-hardness if the problem being reduced from is itself NP-complete. We therefore need to justify that Vertex Cover is NP-complete before we can use it as our starting point. Vertex Cover was proved NP-complete by Richard Karp in his landmark 1972 paper "Reducibility Among Combinatorial Problems", which established 21 problems as NP-complete in a single paper.

The reduction chain that grounds Vertex Cover in the original NP-complete problem is:

3-SAT ≤ₚ Clique ≤ₚ Vertex Cover ≤ₚ Independent Set ← we prove this step

3-SAT is NP-complete by Cook's theorem (1971) — the foundational result that proved the first NP-complete problem from first principles. Clique ≤ₚ Vertex Cover: a clique of size k in G corresponds to an independent set of size k in the complement graph Ḡ, and the complement of that IS is a VC of size |V|−k in Ḡ — a standard complement argument. We prove Vertex Cover ≤ₚ Independent Set (this step, below) using the same complement duality directly on the original graph. Each arrow ≤ₚ denotes a polynomial-time many-one reduction, so NP-hardness propagates along the entire chain.

2a — Reduction Construction

CLO-5 · Construction
Formal Mapping f

Given a Vertex Cover instance (G, k), output the Independent Set instance f(G, k) = (G, |V| − k). The graph is unchanged; only the parameter is transformed. This is a complement reduction exploiting the fact that S is an IS iff V\S is a VC.

Why the same graph works: an independent set and a vertex cover are always complementary subsets of V. One covers all edges; the other touches none. So the same graph G witnesses both problems simultaneously.
Reduction Diagram — Concrete Worked Example (CLO-5 · Gadgets Explicit)
INPUT: Vertex Cover Instance OUTPUT: Independent Set Instance f 0 VC 1 VC 2 VC 3 IS (G, k = 3) Does G have a VC of size 3? → YES: {0,1,2} VC vertex IS vertex 0 1 2 3 IS ✓ (G, k′ = |V|−k = 4−3 = 1) Does G have an IS of size 1? → YES: {3} f(G, 3) = (G, 1) · Same graph G · VC size k=3 ⇐⇒ IS size |V|−k = 1
Graph G
4 vertices {0,1,2,3}
4 edges: 0–1, 1–2, 0–2, 2–3
VC Instance Input
C = {0,1,2}, size k = 3
Every edge is covered ✓
IS Instance Output
S = V \ C = {3}, size = 4−3 = 1
No edges inside {3} ✓
The Mapping f
f(G, k=3) = (G, k′=1)
Same graph, k′ = |V|−k ✓

2b & 2c — Proving the ⇐⇒ (Both Directions)

CLO-5 · Forward & Backward
The Core Claim of the Reduction
G has a Vertex Cover of size k  ⇐⇒  G has an Independent Set of size |V| − k

The symbol ⇐⇒ means "if and only if" — both statements are always true or always false together, on every possible graph. This is what makes the reduction valid: solving IS automatically solves VC, and vice versa. We prove this in two halves — ⟹ (2b) and ⟸ (2c) — and together they establish the full ⇐⇒.

2b — First half   ⟹   VC YES means IS YES

CLO-5 · Forward
What this claims — in plain English
If you can find a set of vertices C that covers every edge (a Vertex Cover of size k), then the leftover vertices — everything not in C — automatically form a group where no two are connected (an Independent Set of size |V| − k).
Formal statement: If C ⊆ V is a vertex cover with |C| = k, then S = V \ C is an independent set with |S| = |V| − k.

How we prove it: We use contradiction — assume the leftover set is not independent, then show that assumption breaks the definition of a vertex cover.

Assumption — suppose the leftover set S is NOT independent

If S is not independent, then somewhere inside S there must be two vertices — call them u and v — that are connected by an edge. Both are in S, meaning both are outside C (since S = V \ C).

Contradiction — C fails to cover the edge u–v

A Vertex Cover must have at least one endpoint of every edge inside C. But edge u–v has both endpoints outside C — so C misses this edge entirely. That contradicts C being a vertex cover.

Conclusion — S must be independent ✓

The assumption led to a contradiction, so it must be false. Therefore S = V \ C is an independent set. Its size is |V| − |C| = |V| − k.  ⟹ proved ✓

One-sentence summary of 2b: If C covers all edges, then no edge can have both endpoints outside C — so the outside vertices form an IS.

2c — Second half   ⟸   IS YES means VC YES

CLO-5 · Backward
What this claims — in plain English
If you have a group of vertices where no two are connected (an Independent Set of size |V| − k), then the remaining vertices — everything not in that group — automatically cover every edge (a Vertex Cover of size k).
Formal statement: If S ⊆ V is an independent set with |S| = |V| − k, then C = V \ S is a vertex cover with |C| = k.

How we prove it: We prove it directly — we pick any edge and show C must touch it, using only the definition of an independent set.

Pick any edge in the graph

Take any edge — call its two endpoints u and v. We need to show that at least one of them is in C.

Use the definition of an independent set

S is an independent set — by definition, no two vertices inside S share an edge. But u and v do share an edge. So they cannot both be inside S. That means at least one of them — say u — must be outside S.

That vertex is in C — the edge is covered ✓

C is defined as every vertex not in S. Since u is outside S, u is in C. The edge u–v has an endpoint in C, so it is covered. Since this works for any edge we choose, C covers every edge in the graph — C is a Vertex Cover.  ⟸ proved ✓

Size check: |C| = |V| − |S| = |V| − (|V| − k) = k.   The cover has exactly size k, as required.  ✓
One-sentence summary of 2c: An IS has no internal edges, so every edge must have an endpoint outside the IS — meaning the outside vertices cover all edges.
Both halves proved. 2b showed ⟹ and 2c showed ⟸. Together they establish the full biconditional: ⇐⇒ G has a VC of size k if and only if G has an IS of size |V| − k. The reduction is correct.

2d — Polynomiality of the Construction

CLO-5 · Polynomiality
Why the Reduction Itself Is Fast (Polynomial Time)

A reduction is only valid if it runs in polynomial time. Otherwise the reduction itself could be doing the hard work, which would make the whole argument circular. Here is exactly what the reduction function f(G, k) does and how long each part takes:

Task 1 — Copy the graph G

We keep the same graph and pass it straight through to the IS solver. Copying a graph means copying its vertex list and edge list. That takes time proportional to the size of the input: O(|V| + |E|) — linear in the input size.

Task 2 — Change the target number from k to |V| − k

This is a single subtraction. We already know |V| (the number of vertices), so computing |V| − k is one arithmetic operation: O(1).

Total time for the reduction
Copy graph: O(|V| + |E|) — proportional to input size Compute |V| − k: O(1) — one subtraction Total: O(|V| + |E|) — polynomial. The reduction is valid.  ∎

This is called a polynomial-time many-one reduction (also known as a Karp reduction). The fact that it runs in polynomial time is what allows NP-hardness to transfer from Vertex Cover to Independent Set.

Why this matters: if the reduction itself were exponential, we couldn't conclude anything — we could be hiding the hard work inside f. Polynomial-time reduction is what makes NP-hardness transfer.
Conclusion & Logical Chain
CLO-5 · Complete
Step 1 established
Independent Set ∈ NP — the verifier runs in O(n²).
Step 2 established
Vertex Cover ≤ₚ Independent Set — the complement reduction is correct and polynomial.
Why these two steps together imply NP-completeness: Vertex Cover is a known NP-complete problem (proved by Karp, 1972). Step 2 shows that any efficient solver for Independent Set could be used to solve Vertex Cover — so IS is at least as hard as VC, making IS NP-hard. Step 1 shows IS is in NP — it is no harder than the class NP. A problem that is both NP-hard and in NP is, by definition, NP-complete.

Therefore Independent Set ∈ NP-Complete. ∎ QED

★

Interactive Reduction Example

Enter a Vertex Cover instance to see the equivalent Independent Set instance derived by the complement reduction.

Vertex Cover Instance
Graph G, k =
|V| = 6
Does G have a VC of size k?
⟹
f(G,k) = (G, |V|−k)
Independent Set Instance
Same graph G, k' = 4
|V| − k = 6 − 2 = 4
Does G have an IS of size |V|−k?
Example Instantiation

For the 5-cycle C₅ (|V|=5): If C₅ has a Vertex Cover of size k=3 (vertices {0,1,3}), then the reduction says: C₅ has an IS of size |V|−k = 5−3 = 2. Indeed, {2,4} is an IS of size 2. Both instances are YES-instances. ✓

Comparison Mode — Brute-Force vs Greedy
CLO-4 · 10 marks
Run both algorithms on the same graph and watch every decision side by side.
CLO-4 Rubric Items Covered in This Section
✓
Brute-force implemented: Enumerates all 2ⁿ subsets, checks independence, finds exact maximum IS.
✓
Practical algorithm implemented: Min-degree greedy heuristic, O(n²), handles large graphs.
✓
Side-by-side comparison: Both algorithms step in sync; IS sizes, decisions, and operations shown.
✓
Scalability shown: Table below demonstrates brute-force becomes infeasible as n grows.
🔨 Brute Force — How it works

Tries every possible subset of vertices — all 2ⁿ of them. For each subset it checks two things: is the size ≥ k, and does any edge exist inside it? The largest valid subset found is the maximum independent set. Always correct, always slow.

🌿 Greedy — How it works

Makes one local decision at a time: pick the vertex with the fewest remaining neighbours, add it to the IS, remove it and all its neighbours, repeat. Runs in O(n²). Always fast, sometimes suboptimal.

Random graph — n vertices
Edge density (0–1)
🔨 Brute Force (Exact)
O(2ⁿ · n²) time
0
Subsets checked
—
IS Size found
—
Time (ms)
Press ⚡ Build to load a graph.
🌿 Greedy Heuristic
O(n²) time
0
Iterations
—
IS Size found
—
Time (ms)
Press ⚡ Build to load a graph.
Step 0 / 0
Load a graph and press Build to start.
Slow Fast
🌿 Greedy Heuristic O(n²)
✅ When to use it

Use greedy when your graph is large (n > 20), when an approximate answer is acceptable, or when speed matters more than finding the exact maximum. It works well in practice for sparse graphs and real-world scheduling or network problems where a near-optimal solution is good enough.

❌ When it fails

Greedy can produce a suboptimal IS on adversarial graphs — especially those with high-degree "hub" vertices whose removal eliminates many otherwise-good candidates. It has no provable approximation guarantee: on worst-case inputs it can miss the optimal IS by a factor of O(n / log n) (Håstad 1999). It also gives different answers depending on how ties are broken.

⚡ Key difference

Greedy makes one pass through the graph and never backtracks. Each decision is locally optimal but globally blind — it cannot "see" that an early pick might cut off a larger IS later on.

🔨 Brute Force (Exact) O(2ⁿ·n²)
✅ When to use it

Use brute force only on very small graphs (n ≤ 20 or so) where the exact maximum IS is required. It is the right choice for verification (confirming greedy's answer is optimal or not), for teaching purposes, and for exhaustive search in puzzles or small constraint-satisfaction problems.

❌ When it fails

Brute force becomes completely impractical beyond ~25 vertices. At n=50 it would need to check 2⁵⁰ ≈ 10¹⁵ subsets — millions of years of computation on modern hardware. It also provides no partial answer if interrupted: it must finish all 2ⁿ checks before it can declare a winner.

⚡ Key difference

Brute force checks all 2ⁿ subsets and is therefore guaranteed to find the exact maximum IS. It trades time for correctness — the opposite tradeoff to greedy.

📊 Head-to-Head: The Core Difference
O(n²)
Greedy — fast, approximate
vs
O(2ⁿ·n²)
Brute Force — slow, exact

For n = 10: greedy does ~100 operations; brute force checks 1 024 subsets — both feasible, but brute force is ~10× slower. For n = 30: greedy does ~900 operations in microseconds; brute force needs ~10⁹ checks — taking over a second. For n = 50: greedy finishes instantly; brute force would take millions of years. This exponential gap is why NP-complete problems are considered intractable and why no known algorithm bridges this divide.

Scalability Analysis — Operations Count
CLO-4
Brute-force becomes infeasible; greedy scales linearly
|V|Brute-Force (2ⁿ) Greedy (n²)SpeedupBF Feasible?
⚠️ Greedy Approximation Warning

Greedy finds a valid (not necessarily maximum) independent set. For Independent Set, no polynomial approximation within n^(1-ε) of optimal exists unless P=NP (Håstad 1999). Greedy is used as a practical heuristic, not a guaranteed approximation algorithm.

Benchmark — Brute-Force vs Greedy
Measure actual operation counts and wall-clock time across a range of graph sizes. Brute-force is disabled for n > 18 and clearly labelled.
📊
No benchmark data yet
Configure the parameters above and click Run Benchmark to measure both algorithms across a range of graph sizes.