Greedy Algorithms8 sections · 316 units
Open in Course

Greedy vs Brute Force

Why greedy is faster

Brute force tries every possible solution and picks the best. For nn items, this often means O(2n)O(2^n) or O(n!)O(n!) time. It may also use O(n)O(n) to O(2n)O(2^n) space to store candidates. Unusable for large inputs.

Greedy makes one choice per step without looking back. It gives O(n)O(n) or O(nlog⁡n)O(n \log n) time, depending on whether sorting is needed. Space is usually O(1)O(1) extra beyond the input.

The tradeoff: brute force always finds the optimum, greedy only works when the greedy choice property holds. But when greedy works, it is dramatically faster.