简体   繁体   English

最近邻算法和贪心算法有什么区别?

[英]What are the differences between Nearest Neighbor Algorithm and Greedy Algorithm?

I'm trying to develop 2 different algorithms for Travelling Salesman Algorithm (TSP) which are Nearest Neighbor and Greedy.我正在尝试为旅行推销员算法 (TSP) 开发 2 种不同的算法,它们是最近邻算法和贪心算法。 I can't figure out the differences between them while thinking about cities.在考虑城市时,我无法弄清楚它们之间的差异。

I think they will follow the same way because shortest path between two cities is greedy and the nearest at the same time.我认为他们会遵循同样的方式,因为两个城市之间的最短路径是贪婪的,同时也是最近的。 which part am i wrong?我错了哪一部分? Can you explain with a few cities example thank you!你能用几个城市的例子解释一下吗谢谢!

Check out this link here: https://en.wikipedia.org/wiki/Travelling_salesman_problem It gives an in depth description of the problem.在此处查看此链接: https://en.wikipedia.org/wiki/Travelling_salesman_problem它对问题进行了深入描述。 There are many different solutions to the TSP, the Nearest Neighbour solution is a Greedy Solution, so these are indeed the same. TSP 有许多不同的解决方案,最近邻解决方案是贪婪解决方案,所以这些确实是相同的。

Answer is NN Algorithm basically creates segments to closest nodes that it can reach, Greedy is the method of it but it directly takes the node which is the closest to current node.答案是 NN 算法基本上将段创建到它可以到达的最近节点,贪婪是它的方法,但它直接取离当前节点最近的节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM