Problem Solving

Concept shape

Practice pattern
0
1
2
3
4
5
Definition

A greedy algorithm makes the locally best choice and commits to it.

Step 1 / 5
Concept shape
Current lesson

Greedy Thinking Lab

Problem Solving Practice pattern

Greedy Thinking

Welcome to the Greedy Thinking concept lab. A greedy algorithm makes the locally best choice and commits to it. The must know points are: Must prove local choices lead to global optimum. Sorting often comes first. Not every optimization problem is greedy. The common operations are: sort by rule, choose best next, commit choice. The complexity shape is Often O(n log n) due to sorting. Watch out for these pitfalls: Using greedy without proof. Choosing the wrong sorting rule. Related algorithms include Activity Selection, Merge Intervals.

Concept details

A greedy algorithm makes the locally best choice and commits to it.

Must know

  • Must prove local choices lead to global optimum.
  • Sorting often comes first.
  • Not every optimization problem is greedy.

Complexity

Often O(n log n) due to sorting

Open deeper visual structure lesson
1.0x