I need to prove that there's no greedy algorithm that can obtain the
optimal solution for a given problem.
Well, that's going to depend on the definition of the property you chose.
Have a look for example on the graph coloring problem, and assume you have an oracle M
that given a partially colored graph, returns true if and only if there is a graph coloring for it.
Now, using this oracle, a greedy algorithm can be as follows:
for each vertex v:
for each color c:
temporarly color v with c
run M on partially colored graph
if M yields true, make c constant to v, and abort the inner loop
The above algorithm is coloring the graph in a greedy manner, chosing one vertex at a time, according to the answer of the oracle M
. (Choosing the best answer of M
and assigning it to each vertex and color, where set of answers is false or true)
Does it feel like cheating? Probably, because there is no known such M
that runs in polynomial time, but if you run an exponential algorithm that creates M
, there is definetly a greedy algorithm for it.
You can however prove that there is no KNOWN algorithm that greedily chooses in polynomial time (or any other polynomial algorithm for that matter) that yields an optimal answer for graph coloring, since graph coloring is NP-Complete, and we don't know any algorithm that solves NPC problems efficiently (and most believe such does not exist).
However, if at some point we will prove P=NP, we can efficiently calculate M
, and we will get an efficient greedy algorithm that solves graph coloring.