1 / 15

§ 6.5 - 6.8 Algorithms, Algorithms, Algorithms

§ 6.5 - 6.8 Algorithms, Algorithms, Algorithms. Recall that an algorithm is a set of procedures or rules that, when followed, lead to a ‘solution’ to a particular problem.

Download Presentation

§ 6.5 - 6.8 Algorithms, Algorithms, Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. § 6.5 - 6.8 Algorithms, Algorithms, Algorithms

  2. Recall that an algorithm is a set of procedures or rules that, when followed, lead to a ‘solution’ to a particular problem.

  3. Think back to the `Homer` example from yesterday.The method we used there can be written as a slightly more formal algorithm: • The Brute-Force Algorithm • First, make a list of all the possible Hamiltonian circuits of the graph. • For each circuit, calculate its totalweight by summing the weights of all the edges traveled. • Find the circuits* with the least total weight. Any of these can be chosen as an optimal H.C.

  4. THE METHOD USED IN OUR OTHER (EVEN GEEKIER) EXAMPLE FROM YESTERDAY CAN ALSO BE MADE A BIT MORE FORMAL. . . • THE NEAREST NEIGHBOR ALGORITHM • PICK ANY VERTEX AS A STARTING POINT. • FROM THE STARTING VERTEX GO TO ITS NEAREST NEIGHBOR--THE NEAREST VERTEX FOR WHICH THE CORRESPONDING EDGE HAS THE SMALLEST WEIGHT. • CONTINUE BUILDING THE CIRCUIT, ONE VERTEX AT A TIME, ALWAYS CHOOSING THE NEAREST NEIGHBOR FROM THE VERTICES THAT HAVE NOT BEEN TRAVELED YET. • FROM THE LAST VERTEX RETURN TO YOUR STARTING POINT.

  5. So which of these methods is better? The Brute-Force Method will always give the optimal solution, but it is inefficient. The Nearest NeighborAlgorithm on the other hand is efficient but not always accurate. Given its efficiency, one might ask if there is a way to improve on the second algorithm.

  6. The Repetitive Nearest-Neighbor Algorithm • Let X be any vertex. Apply the Nearest-Neighbor Algorithm using X as the starting point and calculate the total cost for the circuit. • Repeat the process for each of the other vertices of the graph. • Choose the best Hamiltonian circuit you find. If we have designated a starting vertex, then rewrite the circuit with that vertex as the reference point.

  7. Example: The Galactica needs to survey a set of planets (A, B, C, D, E, F, G) in order to find water for the Fleet. the Commander has asked the helm to chart the course that will use the lowest amount of tylium fuel. LET US REVISIT THE SECOND EXAMPLE FROM YESTERDAY, ARMED THIS TIME WITH THE REPETITIVE NEAREST NEIGHBOR ALGORITHM. . .

  8. THE FOLLOWING TABLE TELLS US HOW MANY TONS OF TYLIUM IT TAKES TO TRAVEL FROM ONE PLANET TO ANOTHER: YESTERDAY WE FOUND THAT THE N.N. ALGORITHM APPLIED TO A GAVE US THE FOLLOWING CIRCUIT AND WEIGHT: a,f,g,c,b,d,e,a15+13+28+30+60+20+35=201

  9. THE FOLLOWING TABLE TELLS US HOW MANY TONS OF TYLIUM IT TAKES TO TRAVEL FROM ONE PLANET TO ANOTHER: NOW STARTING WITH B WE GET: 30+28+13+15+28+20+80=214b,c,g,f,a,d,e,b

  10. THE FOLLOWING TABLE TELLS US HOW MANY TONS OF TYLIUM IT TAKES TO TRAVEL FROM ONE PLANET TO ANOTHER: NOW STARTING WITH C WE GET: 28+13+15+28+20+80+30=214c,g,f,a,d,e,b,c

  11. THE FOLLOWING TABLE TELLS US HOW MANY TONS OF TYLIUM IT TAKES TO TRAVEL FROM ONE PLANET TO ANOTHER: SIMILARLY FOR d, e, f AND g WE GET: 20+35+15+13+28+50+60=221d,e,a,f,g,c,b,d 20+28+15+13+28+30+80=214e,d,a,f,g,c,b,e 15+22+29+20+48+30+65=229f,a,g,d,e,c,b,e 13+15+28+20+48+30+50=204g,f,a,d,e,c,b

  12. The Cheapest-Link Algorithm • Pick the edge with the smallest weight first. Mark the edge (or otherwise note that you have chosen it). • Pick the next ‘cheapest’ edge. Mark or note it. • Continue picking the ‘cheapest’ edge available and mark the edge as long as (a) it does not close a circuit and (b) it does not result in three edges coming out of a single verrtex. • When there are no more vertices left, close the circuit.

  13. B 75 30 60 65 WE CAN USE THIS NEW ALGORITHM ON OUR SECOND EXAMPLE: 50 A C 28 28 48 22 35 40 35 50 29 G D 30 15 32 20 13 80 40 F E

  14. B 75 30 60 65 50 A C 28 28 48 22 35 40 35 50 29 G D 30 15 32 20 13 80 40 F E

  15. A Few Final notes: • The Nearest-Neighbor, Repetitive N.N. and Cheapest-Link Algorithms are all approximate algorithms. • I.e. - The routes they make may not be the optimal solution, but they are usually better than a random approach. • The amount of time needed to arrive at these approximate routes is much shorter than using the Brute-Force method; which is why they are used more often in ‘real-life’ situations.

More Related