Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading example for the Greedy Algorithms section #200

Open
efeberkeevci opened this issue Sep 26, 2021 · 1 comment
Open

Misleading example for the Greedy Algorithms section #200

efeberkeevci opened this issue Sep 26, 2021 · 1 comment

Comments

@efeberkeevci
Copy link

In the Greedy Algorithms section, coin change problem is provided as an example. This creates an impression that every coin change problem can be solved with greedy approach. This is incorrect since using greedy approach in some coin sets gives the incorrect result and needs to be solved with dynamic programming.

More info: https://stackoverflow.com/questions/13557979/why-does-the-greedy-coin-change-algorithm-not-work-for-some-coin-sets

@Ziniddoug
Copy link

A deceptive example for the Greedy Algorithms section is the Traveling Salesman Problem.

In this example, let's consider a set of cities that need to be visited by a salesperson. The goal is to find the shortest possible route that passes through all cities and returns to the starting point.

A naive greedy algorithm to solve this problem would always select the closest available city at each step. In other words, at each stage, the salesperson would choose the nearest city from the current city and add it to the route.

However, the Traveling Salesman Problem is an NP-complete problem, which means that there is no known efficient solution to solve it in polynomial time. The naive greedy algorithm does not take into account the global optimality of the solution and can therefore provide suboptimal solutions.

While the greedy algorithm may provide reasonable solutions for smaller instances of the problem, it does not guarantee the optimal solution in all cases. Therefore, this deceptive example of the Traveling Salesman Problem highlights the need for more sophisticated approaches, such as dynamic programming or exhaustive search algorithms, to efficiently solve NP-complete problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants