Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1- Several possible algorithms might come to mind to solve this problem. Perhaps the most popular idea is the nearest-neighbor heuristic algorithm is used to

image text in transcribed

image text in transcribed

1- Several possible algorithms might come to mind to solve this problem. Perhaps the most popular idea is the nearest-neighbor heuristic algorithm is used to solve the shortest tour problem. Starting from some point PO, we walk first to its nearest neighbor P1 . From P1 , we walk to its nearest unvisited neighbor, thus excluding only PO as a candidate. We now repeat this process until we run out of unvisited points, at which time we return to PO to close off the tour. In pseudocode, the nearest-neighbor heuristic looks like this: Figure: A good example for the nearest neighbor heuristic NearestNeighbor TSP(P) Pick and visit an initial point PO from P P = po i=0 While there are still unvisited points i=i+1 Select Ps to be the closest unvisited point to Ps-1 Visit oui Return to Po from P-1 This algorithm has a lot to recommend it. It is simple to understand and implement. It makes sense to visit nearby points before we visit faraway points if we want to minimize the total travel time. The algorithm works perfectly on the example in Figure v. The nearest neighbor rule is very efficient, for it looks at each pair of points (Pi, Pj) at most twice, once when adding Pi to the tour, the other when adding Pj . Against all these positives there is only one problem. This algorithm is completely wrong. IL Figure: A bad example for the nearest neighbor heuristic Explain how can it be wrong? 2- The knapsack problem is as follows: given a set of integers S= {s1, s2, sn} and a target number 7, find a subset of S which adds up exactly to T. For example, there exists a subset within S = {1, 2, 5, 9, 10} that adds up to T = 22 but not T = 23. Find counterexamples to each of the following algorithms for the knapsack problem. That is, giving an S and T such that the subset is selected using the algorithm does not leave the knapsack completely full, even though such a solution exists. (a) Put the elements of S in the knapsack in left to right order if they fit, i.e. the first-fit algorithm. (b) Put the elements of S in the knapsack from smallest to largest, i.e. the best-fit algorithm. (c) Put the elements of S in the knapsack from largest to smallest. 3- Prove the correctness of the following sorting algorithm. function bubblesort (A : list[1 ...n]) var int i, j for i from n to 1 for j from 1 to i - 1 if (A[j] > A[j + 1]) swap the values of A[j] and A[j + 1] 4- A sorting algorithm takes 1 second to sort 1,000 items on your local machine. How long will it take to sort 10,000 items... (a) if you believe that the algorithm takes time proportional to n2, and (b) if you believe that the algorithm takes time roughly proportional to n log n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions

Question

2. Identify conflict triggers in yourself and others

Answered: 1 week ago