greedy algorithm in data structure with example