The greedy algorithm almost never succeeds in finding the optimal solution. In cases where this happens, it depends a lot on the problem itself. As Ted Hopp explained, with convex curves you can find a global optimal option, assuming that you should, of course, find the maximum objective function (on the contrary, concave curves also work if you need to minimize). Otherwise, you will almost certainly be stuck in local optima. This assumes that you already know the objective function.
Another factor I can think of is the neighborhood function. Some areas, if large enough, will cover both global and local maxima so that local maxima can be avoided. However, you cannot make the neighborhoods too large or the search will be slow.
In other words, regardless of whether you find the global optimal or not with greedy algorithms, the problem is specific, although in most cases you will not find the global optimal.
Dhruv gairola
source share