Convert to greedy iterative algorithm