Greedy Algorithms8 sections · 316 units
Open in Course

Variant - Weighted Activity Selection

When greedy fails

What if activities have weights (profits)? Maximize total weight of selected activities.

Example: activities = [(11, 44, 33), (33, 55, 22), (55, 77, 44)]. Weights: 33, 22, 44. Greedy by end time: (1,4) then (5,7). Total weight: 33 + 44 = 77. Alternative: (3,5) then (5,7). Total weight: 22 + 44 = 66. Greedy wins here.

But with different weights, greedy can fail. Weighted activity selection needs DP. The weight breaks the greedy property. A low-weight activity ending early might block high-weight activities.