Convex Hull Trick

You know QI-based optimizations. Now meet recurrences as lines and query minimum/maximum with CHT.

43 lessons
175 min
Codeforces: 1900-2500LeetCode: 2100-2500

Lessons

1. Intro

The Goal

4m

2. A Different Pattern

The problem

4m

3. Vocabulary - Linear Function

The building block

4m

4. Rewriting the DP

The transformation

5m

5. Quiz: Linear Form Recognition

Identifying CHT applicability

3m1 problems

6. The Key Observation

Lines in a plane

4m

7. Vocabulary - Lower Envelope

The structure

4m

8. Quiz: Lower Envelope

Understanding the geometry

3m1 problems

9. Why Most Lines Don't Matter

The pruning

4m

10. What Is the Convex Hull Trick?

Core idea

4m

11. When Queries Are Sorted

The simple case

4m

12. The Deque Approach

Data structure

4m

13. Deque Operations - Walkthrough

Tracing the deque maintenance

4m

14. Adding a New Line

Maintaining the hull

5m

15. Quiz: Deque Invariant

Why we pop from back

3m1 problems

16. Querying the Minimum

Finding the best line

4m

17. CHT Query - Walkthrough

Tracing a query

4m

18. Why O(n) Total

Amortized analysis

4m

19. Visualizing CHT

Mental model

4m

20. Codeforces 319C Kalila and Dimna - Problem Statement

CF 319C

3m1 problems

21. Codeforces 319C Kalila and Dimna - The DP

State and transition

5m

22. Codeforces 319C Kalila and Dimna - CHT Form

The transformation

5m

23. Codeforces 319C Kalila and Dimna - Why It Works

The conditions

4m

24. Codeforces 319C Kalila and Dimna - Implementation

The code

7m1 problems

25. Codeforces 319C Kalila and Dimna - Walkthrough

Tracing the full solution

4m

26. Lessons from CHT

summary

5m

27. Challenge: Non-Sorted Slopes

Handling arbitrary order

4m

28. When Queries Aren't Sorted

The general case

4m

29. Binary Search on the Hull

O(log n) queries

4m

30. Vocabulary - Li Chao Tree

Alternative structure

4m

31. Li Chao Tree - Walkthrough

Understanding the structure

4m

32. Quiz: Li Chao vs Deque

Choosing the right structure

3m1 problems

33. Common Mistakes

What to avoid

4m

34. Commando - Problem Statement

Classic CHT problem

3m

35. Commando - Implementation

Handling maximization

5m

36. Covered Walkway - Problem Statement

Another classic

3m

37. Quiz: Covered Walkway Algebra

Deriving the linear form

3m1 problems

38. Challenge: 2D CHT

Higher dimensions

4m

39. Pattern - Convex Hull Trick

Recognition

4m

40. Pattern - CHT Recognition

When to apply CHT

4m

41. Implementation Tips

Practical advice

5m

42. What's Next

Preview of Monotonic Queue

4m

43. Section Recap

What we learned

5m

Practice Problems

1.

Covered with full walkthrough in this section.

2.

The canonical CHT problem. Optimal substructure where cost depends linearly on previous state, perfect for convex hull optimization.

3.
Product SumCodeforceshard

Requires CHT in both directions. Tests understanding of when slopes are monotonic vs need Li Chao tree.

4.

Elegant geometry problem reducible to CHT. Requires insight to transform rectangle selection into linear DP.

5.
Escape Through LeafCodeforceshard

CHT on trees with small-to-large merging. Combines convex hull with tree DP and DSU-on-tree.

6.
Cats TransportCodeforceshard

Multi-dimensional DP with CHT optimization. Teaches how to reduce O(n²k) to O(nk log n).

7.

Geometry + CHT combination. Requires translating projection constraints into convex hull queries.

8.
Long Way HomeCodeforceshard

Dijkstra + CHT combination. Models flight costs as linear functions requiring convex hull queries.

9.

Classic DP with quadratic cost. Natural introduction to CHT before harder variants.

10.
Frog Jump IILeetCodemedium

Simpler jump optimization. Good warmup for understanding optimal substructure in CHT problems.

11.

DP with binary search. Understanding interval DP optimization leads naturally to CHT ideas.

12.

Frog jumping with quadratic cost - the canonical convex hull trick problem.

Ready to start learning?

Access all 43 lessons with interactive content and progress tracking.