raveling Salesman Problem 推销员问题这个问题仅仅是指数时间复杂度问题的例子,此处不要求理解和掌握,只要记住推销员问题可以是指数时间复杂度即可。Input: There are n cities.Output: Find the shortest tour from a particular city that visit each city exactly once beforereturning to the city where it started (Hamiltonian circuit).A Hamiltonian circuit can be represented by a sequence of n+1 cities v1 , v2 , …, vn , v1 , where thefirst and the last are the same, and all the others are distinct.Exhaustive search approach: Find all tours in this form, compute the tour length and find theshortest among them按照上面这种思路,一共要考虑 种不同的路线(指数时间复杂度)。Knapsack Problem 背包问题这个问题仅仅是指数时间复杂度问题的例子,此处不要求理解和掌握,只要记住背包问题可以是指数时间复杂度即可。Input: Given n items with weights w1 , w2 , …, wn and values v1 , v2 , …, vn , and a knapsack withcapacity W.Output: Find the most valuable subset of items that can fit into the knapsack.Application: A transport plane is to deliver the most valuable set of items to a remote locationwithout exceeding its capacityExhaustive search approach: Try every subset of the set of n given items, compute total weight ofeach subset and compute total value of those subsets that do NOT exceed knapsack's capacity按照上面这种思路,一共要考虑 种不同的路线(指数时间复杂度)。for i = 1 to n-1 dobeginkey = a[i]pos = 0while (a[pos] < key) && (pos < i) dopos = pos + 1shift a[pos], …, a[i-1] to the righta[pos] = keyend
Question
raveling Salesman Problem 推销员问题这个问题仅仅是指数时间复杂度问题的例子,此处不要求理解和掌握,只要记住推销员问题可以是指数时间复杂度即可。Input: There are n cities.Output: Find the shortest tour from a particular city that visit each city exactly once beforereturning to the city where it started (Hamiltonian circuit).A Hamiltonian circuit can be represented by a sequence of n+1 cities v1 , v2 , …, vn , v1 , where thefirst and the last are the same, and all the others are distinct.Exhaustive search approach: Find all tours in this form, compute the tour length and find theshortest among them按照上面这种思路,一共要考虑 种不同的路线(指数时间复杂度)。Knapsack Problem 背包问题这个问题仅仅是指数时间复杂度问题的例子,此处不要求理解和掌握,只要记住背包问题可以是指数时间复杂度即可。Input: Given n items with weights w1 , w2 , …, wn and values v1 , v2 , …, vn , and a knapsack withcapacity W.Output: Find the most valuable subset of items that can fit into the knapsack.Application: A transport plane is to deliver the most valuable set of items to a remote locationwithout exceeding its capacityExhaustive search approach: Try every subset of the set of n given items, compute total weight ofeach subset and compute total value of those subsets that do NOT exceed knapsack's capacity按照上面这种思路,一共要考虑 种不同的路线(指数时间复杂度)。for i = 1 to n-1 dobeginkey = a[i]pos = 0while (a[pos] < key) && (pos < i) dopos = pos + 1shift a[pos], …, a[i-1] to the righta[pos] = keyend
Solution
这段文字主要介绍了两个问题:旅行商问题和背包问题,这两个问题都是指数时间复杂度的例子。
旅行商问题的输入是n个城市,输出是从特定城市出发,访问每个城市一次,然后返回起始城市的最短路径(哈密顿回路)。穷举搜索方法是找出所有这样的路径,计算路径长度,然后找出其中最短的。这样的思路需要考虑n!种不同的路线,因此是指数时间复杂度。
背包问题的输入是n个物品,每个物品有重量和价值,还有一个背包的容量。输出是能装入背包的最有价值的物品子集。应用场景是运输飞机要将最有价值的物品集合送到远程位置,但不能超过其容量。穷举搜索方法是尝试给定物品集的每个子集,计算每个子集的总重量,然后计算那些不超过背包容量的子集的总价值。这样的思路需要考虑2^n种不同的路线,因此是指数时间复杂度。
最后一段代码是插入排序的一种实现,它的时间复杂度是O(n^2)。
Similar Questions
State travelling salesman problem. How it is related to Hamiltonian circuits?
Describe the traveling salesman problem using dynamic programming and branch and bound
hamiltonian cycle using backtracking algorithmhamiltonian cycle algorithm using backtracking pdfhamiltonian path algorithmhamiltonian cycle examplehamiltonian cycle in daa algorithmhamiltonian cycle np-completehamiltonian path leetcodehamiltonian path problem in toctime complexity of graph coloring using backtrackingtime complexity of travelling salesman problem using branch and boundReport inappropriate predictions
Is Travelling salesman problem NP-hard or NP-Complete? Justify your answer.
The diagram below shows an input network for the minimum-cost flow problem, and the flow (shown in red) in this network at the end of the 2-nd iteration of the Successive Shortest Path algorithm. During the computation, whenever there is a choice of a vertex, the algorithm selects the vertex which is first in the lexicographical order. (This means, for example, that during the first iteration, the algorithm selected vertex p1 from the two available supply vertices, and selected vertex r1 from the two available demand vertices.) Complete the following statements by dragging and dropping appropriate options.There was Blank 1 Question 1 path from p2 to r1 in the residual network at the beginning of the 2-nd iteration.At the end of the 2-nd iteration, the flow saturates Blank 2 Question 1 edges.At the beginning of the 3-rd iteration, the residual supply at vertex p2 is Blank 3 Question 1 .In the residual network constructed in the 3-rd iteration, Blank 4 Question 1 vertices are reachable from vertex p2.The cost of the path selected in the residual network in the 3-rd iteration is Blank 5 Question 1 .The flow in the input network computed by the end of the 3-rd iteration Blank 6 Question 1 satisfy all supply and demand.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.