An algorithm is called greedy if it follows the problem-solving heuristic of making the locally optimal choice at each stage with the aim of finding a global optimum.
In most situations, a greedy strategy does not lead to the optimal solution. Hence, it is extremely important to reason about the correctness of the greedy strategy before using it to solve a problem.
Let's say you have to maximise the number of tasks that you complete in a 10-hour duration. You are given an array T = [2, 4, 1, 6] where Ti denotes the time required to complete the ith task.
The answer to this question would be 3 as you would choose to do tasks T2, T0 and T1 — which take 1, 2 and 4 hours respect...