Implementing Greedy Algorithm