All greedy algorithms follow a basic structure code example
Example: All greedy algorithms follow a basic structure
getOptimal(Item, arr[], int n)
1) Initialize empty result : result = {}
2) While (All items are not considered)
// We make a greedy choice to select
// an item.
i = SelectAnItem()
// If i is feasible, add i to the
// result
if (feasible(i))
result = result U i
3) return result