0 votes

Consider a greedy algorithm based approach for gold rod question: http://notexponential.com/623/gold-is-a-precious-metal

Show that greedy algorithm based approach is not optimal, by giving a counter example.

in Greedy Algorithms by AlgoMeister (1.6k points)

1 Answer

+1 vote
 
Best answer

When using the greedy method, you will get an approximate answer, which is not always right. For example, due to the length of the wire are given, it is very possible you can't use all wire and has some wire left. In that case, what's has to be left probably be larger than those pieces you choose before.

Here is a simple example: if the wire length is 50.

p1.length = 10, value =60;

p2.length = 20, value =100;

p3.length = 30, value =120;

Using greedy method, you will get p1+p2, value = 160.

However, the right solution is p2+p3, value = 220.

by Active (264 points)
selected by

Related questions

0 votes
8 answers
asked Mar 29, 2019 in Dynamic Programming by Amrinder Arora AlgoMeister (1.6k points)
0 votes
3 answers
asked Mar 19, 2023 in Informed Search by Amrinder Arora AlgoMeister (1.6k points)
+1 vote
1 answer
asked Mar 24, 2021 in CSP by Amrinder Arora AlgoMeister (1.6k points)
The Book: Analysis and Design of Algorithms | Presentations on Slideshare | Lecture Notes, etc
...