hamilton circuits
DESCRIPTION
DISCRETE MATH UNIT 6. HAMILTON CIRCUITS. The Traveling-Salesman Problem. William Rowan Hamilton. Born August 4, 1805 in Dublin, Ireland Died September 2, 1865 in Dublin, Ireland Made many contributions to the Physics field including advancements in the study of optics and dynamics - PowerPoint PPT PresentationTRANSCRIPT
The Traveling-Salesman Problem
•Born August 4, 1805 in Dublin, Ireland
•Died September 2, 1865 in Dublin, Ireland
•Made many contributions to the Physics field including advancements in the study of optics and dynamics
•Introductions to the Mathematics Field•formed the study of quaternion•an extension of complex numbers that allows work in the 3rd and 4th dimensions (symbolized by a bold H)
•invented the Icosian Game (now called Hamilton’s Puzzle)•solved by using Icosian Calculus and these solutions developed into what are now called Hamilton Paths and Hamilton Circuits
Hamilton Path: a path touching every vertex exactly onceevery edge does NOT have to be used
F
B
A C
D
A D E B C F
Hamilton Path Examples
D A B E G F
E B A D E G
G
C
F
NOT a Hamilton Path (Example)
C
E
G
Hamilton Circuit: a circuit touching every vertex exactly onceevery edge does NOT have to be used
F
D
BA
C
EA D B C F E
Hamilton Circuit Examples
D A E F C B
E F D A B C
A
D
F
NOT a Hamilton Circuit (Example)
E
Weight: a numerical value assigned to each edge of the graph
Total Weight: the sum of the edges’ weights used to complete the Hamilton Circuit or Path
Hamilton Circuit Examples
A
E
B
CD
23
5 11
3
8
6
9
A B C D E A
A E B C D A
Hamilton Path Examples
A B C D E
A E B C D
Complete Graph: a graph with N vertices with edges connecting every pair of vertices
each vertex has a degree of (no loops)denoted by the symbol KN
vertices can be named in any order for Hamilton Circuits
1N
Formula for the Number of Hamilton Circuits: )!1( N
Complete Graph Examples
A
CB
A B
CD
A
E B
CD
A
G
C
D
B
F
H
EK3
2 HC’s
K4
6 HC’sK5
24 HC’sK8
5,040 HC’s
Name originates from the classic problem of a traveling-salesman needing to find the cheapest circuit that will allow him to visit multiple clients by traveling to each city just 1 time.• the acronym TSP is used to identify this type of problem
TSPs are used to identify any type of problem that wants to find the cheapest route while touching every vertex exactly 1 time.
Other Examples of TSPs: Package Deliveries School Bus Routes Fabricating Circuit Boards Scheduling Jobs on a Machine Running Errands Around Town
Brute-Force Algorithma) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
Nearest-Neighbor Algorithma) Pick a Starting Vertex.b) Travel to The Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
Repetitive Nearest-Neighbor Algorithma) Pick a Starting Vertex.b) Follow the Steps for the Nearest-Neighbor Algorithm (above).c) Repeat the process until EVERY vertex has become the starting/ending vertex.
Cheapest-Link Algorithma) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
Jerry is the Managing Partner of the “You’re Not Guilty” Law Firm. Part of managing one of the top law firms in the country is having to travel to all 5 of their major offices each month to meet with the partners. While Jerry lives in Dallas, he must visit Chicago, Los Angeles, Miami, and New York. Traveling obviously costs money and in order for clients not to feel like they are being overcharged, Jerry has to make sure that he travels to all 5 cities for as little as possible. We must find the most cost effective means for him to travel between these cities and end back home in Dallas. The cost of flights from each city is found on the following slides.
Los Angeles
Dallas
Chicago
Miami
New York
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a
DALLAS n/a
LOS ANGELES
n/a
MIAMI n/a
NEW YORK
n/a
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS n/a
LOS ANGELES
n/a
MIAMI n/a
NEW YORK
n/a
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
n/a
MIAMI n/a
NEW YORK
n/a
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI n/a
NEW YORK
n/a
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
n/a
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,362
1
35
$952
$937$907
$787
$779
Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,687
13
4
5
$952
$937
$1,147
$787
$864
Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,320
1
2
34
5
$952
$818
$907$864
$779
Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687
DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,220
1
25
4
$952
$818
$799
$787
$864
Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687
DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320
DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,964
1
43
$952
$1,094
$907
$1,147
$864Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687
DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320
DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220
DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,539
1
4
5
3 $952
$1,094
$907
$799
$787
Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687
DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320
DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220
DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964
DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,120
1
2
3
5
$799
$937
$818
$787
$779
Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687
DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320
DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220
DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964
DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,764
1
2
4
$799
$937
$1,094
$787
$1,147
Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120
DAL–MIA–NY–LA–CHI–DAL = $799 + $937 + $1,094 + $787 + $1,147 = $4,764
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687
DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320
DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220
DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964
DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,397
1
3
2
45
$799
$818
$907
$1,094
$779
Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120
DAL–MIA–NY–LA–CHI–DAL = $799 + $937 + $1,094 + $787 + $1,147 = $4,764
DAL–MIA–CHI–NY–LA–DAL = $799 + $907 + $818 + $1,094 + $779 = $4,397
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687
DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320
DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220
DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964
DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,722
1
2
4
3
$799
$1,147$864
$818
$1,094
Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120
DAL–MIA–NY–LA–CHI–DAL = $799 + $937 + $1,094 + $787 + $1,147 = $4,764
DAL–MIA–CHI–NY–LA–DAL = $799 + $907 + $818 + $1,094 + $779 = $4,397
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687
DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320
DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220
DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964
DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539
DAL–MIA–LA–NY–CHI–DAL = $799 + $864 + $1,094 + $818 + $1,147 = $4,722
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,545
1
2
4
5
$1,147
$937
$818
$864$779
Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120
DAL–MIA–NY–LA–CHI–DAL = $799 + $937 + $1,094 + $787 + $1,147 = $4,764
DAL–MIA–CHI–NY–LA–DAL = $799 + $907 + $818 + $1,094 + $779 = $4,397
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687
DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320
DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220
DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964
DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539
DAL–CHI–NY–MIA–LA–DAL = $1,147 + $818 + $937 + $864 + $779 = $4,545
DAL–MIA–LA–NY–CHI–DAL = $799 + $864 + $1,094 + $818 + $1,147 = $4,722
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,864
1
3
2
5
$1,147
$937
$907
$1,094
$779
Brute-Force
Steps for Solving the 5 Cities Examplea) Make a list of ALL possible Hamilton Circuits.b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.
DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120
DAL–MIA–NY–LA–CHI–DAL = $799 + $937 + $1,094 + $787 + $1,147 = $4,764
DAL–MIA–CHI–NY–LA–DAL = $799 + $907 + $818 + $1,094 + $779 = $4,397
DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362
DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687
DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320
DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220
DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964
DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539
DAL–CHI–NY–MIA–LA–DAL = $1,147 + $818 + $937 + $864 + $779 = $4,545
DAL–CHI–MIA–NY–LA–DAL = $1,147 + $907 + $937 + $1,094 + $779 = $4,864
DAL–MIA–LA–NY–CHI–DAL = $799 + $864 + $1,094 + $818 + $1,147 = $4,722
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,120
1
2
3
5
$799
$937
$818
$787
$779
Since each circuit can be traveled in 2 directions, we only had to look at 12 circuits to cover all 24 possibilities.
This circuit can be traveled in either direction.
1
23
5
Steps for the Nearest-Neighbor Algorithma) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.a) Once you get to the last vertex, connect it back to the starting vertex.
While the Brute-Force Algorithm will ALWAYS find the cheapest method, it is not very time friendly. The Nearest-Neighbor Algorithm is a method that allows you to find the “cheapest” circuit without having to analyze every possible circuit.
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 787 $ 779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 787 $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES $ 787 $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 787 (2) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 907 $ 818
DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 787 (2) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 907 $ 818DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 787 (2) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 907 $ 818 (3)
DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 787 (2) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 907 $ 818 (3)
DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 787 (2) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 937
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 907 $ 818 (3)
DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 787 (2) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK $ 937
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 907 $ 818 (3)
DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 787 (2) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 937 (4)
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 907 $ 818 (3)
DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 787 (2) $ 864 $ 1,094
MIAMI $799
NEW YORK
$ 937 (4)
Steps for Solving the 5 Cities Examplea) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 907 $ 818 (3)
DALLAS $ 1,147 $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 787 (2) $ 864 $ 1,094
MIAMI $799 (5)
NEW YORK
$ 937 (4)
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,120
5
32
1
$799
$937
$818
$787
$779
Nearest-Neighbor
Steps for the Repetitive Nearest-Neighbor Algorithma) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.d) Repeat the process until EVERY vertex has become the starting/ending vertex.
If Jerry applied the Nearest-Neighbor Algorithm to his flight plans, he would have been able to find the cheapest route without as much work. The question that follows is, “Why ever use the Brute-Force Method if the Nearest-Neighbor Algorithm works?”
Lets look at the same 5 City Example, but this time find out if the Nearest-Neighbor Algorithm works no matter what city Jerry lives in.
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$779 $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES $779 $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$779 (2) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 799 $ 952
LOS ANGELES
$779 (2) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 799 $ 952
LOS ANGELES
$779 (2) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 799 (3) $ 952
LOS ANGELES
$779 (2) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 799 (3) $ 952
LOS ANGELES
$779 (2) $ 864 $ 1,094
MIAMI $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 799 (3) $ 952
LOS ANGELES
$779 (2) $ 864 $ 1,094
MIAMI $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 799 (3) $ 952
LOS ANGELES
$779 (2) $ 864 $ 1,094
MIAMI $ 937 (4)
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 799 (3) $ 952
LOS ANGELES
$779 (2) $ 864 $ 1,094
MIAMI $ 937 (4)
NEW YORK $ 818
Steps for Solving the 5 Cities Example – Home: Chicagoa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (1) $ 907 $ 818
DALLAS $ 799 (3) $ 952
LOS ANGELES
$779 (2) $ 864 $ 1,094
MIAMI $ 937 (4)
NEW YORK
$ 818 (5)
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,120
3
4
5
2
$799
$937
$818
$787
$779
Nearest-Neighbor
Steps for Solving the 5 Cities Example – Home: Los Angelesa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Los Angelesa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Los Angelesa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 $ 799 $ 952
LOS ANGELES
$ 787 $779 (1) $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Los Angelesa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 $ 799 (2) $ 952
LOS ANGELES
$ 787 $779 (1) $ 864 $ 1,094
MIAMI $ 907 $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Los Angelesa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 818DALLAS $ 1,147 $ 799 (2) $ 952
LOS ANGELES
$ 787 $779 (1) $ 864 $ 1,094
MIAMI $ 907 (3) $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Los Angelesa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 818 (4)
DALLAS $ 1,147 $ 799 (2) $ 952
LOS ANGELES
$ 787 $779 (1) $ 864 $ 1,094
MIAMI $ 907 (3) $ 937
NEW YORK $ 1,094
Steps for Solving the 5 Cities Example – Home: Los Angelesa) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 818 (4)
DALLAS $ 1,147 $ 799 (2) $ 952
LOS ANGELES
$ 787 $779 (1) $ 864 $ 1,094
MIAMI $ 907 (3) $ 937
NEW YORK
$ 1,094 (5)
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,397
23
4
51
$799
$907
$818
$1,094
$779
Nearest-Neighbor
Steps for Solving the 5 Cities Example – Home: Miamia) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Miamia) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Miamia) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 $ 779 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 (1) $ 864 $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Miamia) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 $ 779 (2) $ 952
LOS ANGELES $ 787 $ 1,094
MIAMI $ 907 $799 (1) $ 864 $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Miamia) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 818DALLAS $ 1,147 $ 779 (2) $ 952
LOS ANGELES
$ 787 (3) $ 1,094
MIAMI $ 907 $799 (1) $ 864 $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: Miamia) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 818 (4)
DALLAS $ 1,147 $ 779 (2) $ 952
LOS ANGELES
$ 787 (3) $ 1,094
MIAMI $ 907 $799 (1) $ 864 $ 937
NEW YORK $ 937
Steps for Solving the 5 Cities Example – Home: Miamia) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 818 (4)
DALLAS $ 1,147 $ 779 (2) $ 952
LOS ANGELES
$ 787 (3) $ 1,094
MIAMI $ 907 $799 (1) $ 864 $ 937
NEW YORK
$ 937 (5)
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,120
1
43
2
$799
$937
$818
$787
$779
Nearest-Neighbor
Steps for Solving the 5 Cities Example – Home: New Yorka) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Example – Home: New Yorka) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK $ 818 $952 $ 1,094 $ 937
Steps for Solving the 5 Cities Example – Home: New Yorka) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 $ 907
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 (1) $952 $ 1,094 $ 937
Steps for Solving the 5 Cities Example – Home: New Yorka) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES $779 $ 864
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 (1) $952 $ 1,094 $ 937
Steps for Solving the 5 Cities Example – Home: New Yorka) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907
DALLAS $ 799
LOS ANGELES
$779 (3) $ 864
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 (1) $952 $ 1,094 $ 937
Steps for Solving the 5 Cities Example – Home: New Yorka) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907
DALLAS $ 799 (4)
LOS ANGELES
$779 (3) $ 864
MIAMI $ 937
NEW YORK
$ 818 (1) $952 $ 1,094 $ 937
Steps for Solving the 5 Cities Example – Home: New Yorka) Pick a Starting Vertex.b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time.c) Once you get to the last vertex, connect it back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907
DALLAS $ 799 (4)
LOS ANGELES
$779 (3) $ 864
MIAMI $ 937 (5)
NEW YORK
$ 818 (1) $952 $ 1,094 $ 937
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,120
4
5
1
3
$799
$937
$818
$787
$779
Nearest-Neighbor
Conclusion for the 5 Cities Example
HOME CITY COST OF CIRCUIT
Chicago $ 4,120
Dallas $ 4,120
Los Angeles $ 4,397
Miami $ 4,120
New York $ 4,120
This shows us that if Jerry lived in Los Angeles, it would not have been beneficial for him to trust the Nearest-Neighbor Algorithm. This does not mean he should not live in Los Angeles. It just shows that if using the Nearest-Neighbor Algorithm, you must check it from all the possible vertices to guarantee your answer is the cheapest.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO n/a $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 n/a $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 n/a $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 n/a $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937 n/a
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 1,147 $ 779 $ 799 $ 952
LOS ANGELES
$ 787 $779 $ 864 $ 1,094
MIAMI $ 907 $799 $ 864 $ 937
NEW YORK
$ 818 $952 $ 1,094 $ 937
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 779 $ 799 $ 952
LOS ANGELES
$ 864 $ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 779 $ 799 $ 952
LOS ANGELES
$ 864 $ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:
$779
Cheapest-Link
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 864 $ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 $ 907 $ 818
DALLAS $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 864 $ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:
$779
Cheapest-Link
$787
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907 $ 818
DALLAS $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 864 $ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907 $ 818
DALLAS $ 779 (1) $ 799 $ 952
LOS ANGELES
$ 864 $ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:
$779
Cheapest-Link
$787
$799
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907 $ 818
DALLAS $ 779 (1) $ 799 (3) $ 952
LOS ANGELES
$ 864 $ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907 $ 818DALLAS $ 779 (1) $ 799 (3) $ 952
LOS ANGELES
$ 864 $ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:
$779
Cheapest-Link
$787
$799
$818
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907 $ 818 (4)
DALLAS $ 779 (1) $ 799 (3) $ 952
LOS ANGELES
$ 864 $ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907 $ 818 (4)
DALLAS $ 779 (1) $ 799 (3) $ 952
LOS ANGELES $ 864 $ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:
$779
Cheapest-Link
$787
$799
$818
$864
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907 $ 818 (4)
DALLAS $ 779 (1) $ 799 (3) $ 952
LOS ANGELES $ 864 $ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907 $ 818 (4)
DALLAS $ 779 (1) $ 799 (3) $ 952
LOS ANGELES
$ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907 $ 818 (4)
DALLAS $ 779 (1) $ 799 (3) $ 952
LOS ANGELES
$ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:
$779
Cheapest-Link
$787
$799
$818
$907
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 907 $ 818 (4)
DALLAS $ 779 (1) $ 799 (3) $ 952
LOS ANGELES
$ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 818 (4)
DALLAS $ 779 (1) $ 799 (3) $ 952
LOS ANGELES
$ 1,094
MIAMI $ 937
NEW YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
CITIES CHICAGO DALLASLOS
ANGELESMIAMI
NEW YORK
CHICAGO $ 1,147 $ 787 (2) $ 818 (4)
DALLAS $ 779 (1) $ 799 (3) $ 952
LOS ANGELES
$ 1,094
MIAMI $ 937NEW
YORK
Steps for Solving the 5 Cities Examplea) Pick the edge with the smallest weight first. (if a tie, randomly choose one)b) Pick the next smallest edge. (make sure you mark each edge used – only use once)c) Repeat the process until EVERY vertex has been linked. (using each vertex once)d) Once every vertex has been used, link the last vertex back to the starting vertex.
Los Angeles
Dallas
Chicago
Miami
New York
TOTAL COST:$ 4,120
$779
Cheapest-Link
$787
$799
$818
$937
You Now Know All About