logo

Greedy Strategy



Be greedy to learn new things ...

This algorithm paradigm focusses on local optimality at each step in order to achieve global optimality. This paradigm always chooses the step which benefits the solution immediately.

Under this paradigm, we will be learning :

The algorithm goes like this ...

  • In each iteration i (where i >= 1), we find the least element in the array between the index i and N. (where N is the length of the array)
  • We then swap the (i-1)th element of the array with the least element found.
  • We can observe that at the end of ith iteration, the array between the index 0 and i will be sorted.
  • Similarly, at the Nth iteration, we will have a sorted array.

Click the button below to see how selection sort works ...