# § 6.5 - 6.8 algorithms, algorithms, algorithms

Post on 31-Dec-2015

89 views

Category:

## Documents

Embed Size (px)

DESCRIPTION

§ 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. - PowerPoint PPT Presentation

TRANSCRIPT

• 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.

• 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 total weight 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.

• 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.

• So which of these methods is better?The Brute-Force Method will always give the optimal solution, but it is inefficient.The Nearest Neighbor Algorithm 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.

• 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.

• 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. . .

• 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,a 15+13+28+30+60+20+35=201

ABCDEFGA755028351522B753060806550C503040483528D286040203029E358048204032F156535304013G225028293213

• 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=214 b,c,g,f,a,d,e,b

ABCDEFGA755028351522B753060806550C503040483528D286040203029E358048204032F156535304013G225028293213

• 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=214 c,g,f,a,d,e,b,c

ABCDEFGA755028351522B753060806550C503040483528D286040203029E358048204032F156535304013G225028293213

• 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=221 d,e,a,f,g,c,b,d20+28+15+13+28+30+80=214 e,d,a,f,g,c,b,e15+22+29+20+48+30+65=229 f,a,g,d,e,c,b,e13+15+28+20+48+30+50=204 g,f,a,d,e,c,b

ABCDEFGA755028351522B753060806550C503040483528D286040203029E358048204032F156535304013G225028293213

• 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.

• ABCGFED752250134020403065508035291548356028303228WE CAN USE THIS NEW ALGORITHM ON OUR SECOND EXAMPLE:

• ABCGFED752250134020403065508035291548356028303228

• 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.

Recommended