Proving Greedy Correctness

How do you know greedy works? Learn two proof techniques: the exchange argument and the stays-ahead argument to verify greedy strategies.

42 lessons
120 min
Codeforces: 800-1400LeetCode: 1200-1700

Lessons

1. Intro

Why proofs matter

2m

2. The Problem with Intuition

When feelings fail

3m

3. Two Proof Techniques

Your toolkit

3m

4. Vocabulary - Exchange Argument

Swap to improve

3m

5. Exchange Argument Structure

The template

4m

6. Quiz: Exchange Argument

Test your understanding

1m1 problems

7. Example - Activity Selection Exchange

Proving earliest-end-first

3m

8. Activity Selection - The Exchange

Constructing the swap

4m

9. Activity Selection - Completing the Proof

Induction finishes it

3m

10. When Exchange Works Best

Problem characteristics

3m

11. Vocabulary - Stays Ahead Argument

Always leading

3m

12. Stays Ahead Structure

The template

4m

13. Quiz: Stays Ahead

Test your understanding

1m1 problems

14. Example - Activity Selection Stays Ahead

Alternative proof

3m

15. Activity Selection - Base Case

First activity

3m

16. Activity Selection - Inductive Step

Maintaining the lead

4m

17. Activity Selection - Conclusion

Finishing the proof

3m

18. When Stays Ahead Works Best

Problem characteristics

3m

19. Exchange vs Stays Ahead

Choosing your approach

3m

20. Quiz: Choosing a Technique

Apply your knowledge

1m1 problems

21. Finding Counterexamples

When greedy fails

3m

22. Counterexample - 0/1 Knapsack

Greedy ratio fails

3m

23. Counterexample - Better Example

A clearer failure

3m

24. Counterexample - The Classic

When fractional thinking fails

3m

25. Why Greedy Fails for 0/1 Knapsack

The blocking problem

3m

26. How to Find Counterexamples

Systematic approach

3m

27. Quiz: Counterexample Thinking

Finding failures

1m1 problems

28. Problem - Minimum Waiting Time

Proving shortest-first

3m

29. Minimum Waiting - The Greedy Claim

Shortest first

3m

30. Minimum Waiting - Exchange Proof

Swapping adjacent pairs

4m

31. Minimum Waiting - Algorithm

Simple implementation

3m

32. Problem - Tandem Bicycle

Maximize or minimize speed

3m

33. Tandem Bicycle - Maximize Speed

Pair fast with slow

3m

34. Tandem Bicycle - Minimize Speed

Pair fast with fast

3m

35. Tandem Bicycle - Proof Sketch

Exchange argument

4m

36. Problem - Class Photos

Taller in back row

3m

37. Class Photos - Greedy Solution

Match by rank

3m

38. Class Photos - Proof

Why sorting works

4m

39. Quiz: Class Photos

Apply the algorithm

1m1 problems

40. Common Proof Mistakes

Avoid these errors

3m

41. Practice Strategy

Building proof skills

2m

42. Section Recap

What we learned

2m

Practice Problems

1.
Dragonscodeforces
2.
3.
4.
GCD and MSTcodeforces
5.
Lost Treecodeforces
6.

Ready to start learning?

Access all 42 lessons with interactive content and progress tracking.