You are on page 1of 31

EDGE

PICKING
ALGORITHM
Hamiltonian Circuit
A graph is Hamiltonian if there is a
circuit that passes through each
vertex exactly once.
This path is called a Hamiltonian
circuit
 We’ll find the “best” Hamilton circuits within
a complete graph (one in which all vertices are
connected by exactly one edge).
The Greedy Algorithm and the
Edge-Picking Algorithm will both
give us “efficient” Hamiltonian
circuits in complete
labeled graphs.
EDGE-PICKING ALGORITHM
Finding efficient
Hamiltonian circuits in
complete graphs.
Edge-Picking Algorithm
1. Mark the edge that has the smallest weight.
2. Mark the edge of next-smallest weight, as long as
it does not complete a circuit, and does not add a
third marked edge to a single vertex.
3 Continue until no more edges can be marked. That
is, until all vertices have been used.
4 Return to the starting vertex.
EXAMPLE:
Mark the edge that has the smallest weight.
Mark the edge of next-smallest weight, as long as
it does not complete a circuit, and does not add a
third marked edge to a single vertex.
Mark the edge of next-smallest weight, as long as
it does not complete a circuit, and does not add a
third marked edge to a single vertex.
Mark the edge of next-smallest weight, as long as
it does not complete a circuit, and does not add a
third marked edge to a single vertex.
Total “cost” or
“weight”:
5 + 4 + 3 + 5 + 9 = 26
Comparing Algorithms
Edge-Picking Algorithm
and Greedy Algorithm
Example: miles driven running errands
Home Post Grocery Video Bank
Errand Office Store
Home ----- 14 12 20 23
Post Office 14 ----- 8 12 21
Grocery 12 8 ----- 17 11
Video 20 12 17 ----- 18
Store
Bank 23 21 11 18 -----
Edge-Picking Algorithm
Edge-Picking Algorithm
Edge-Picking Algorithm
Edge-Picking Algorithm
Edge-Picking Algorithm
Edge-Picking Algorithm
Total “cost” or “weight”: 8
+ 11 + 12 + 20 + 23 = 74
Greedy Algorithm
1. Choose a vertex as a starting point, and travel
along the edge that has the smallest weight.
2. After arriving at the next vertex, travel along the
edge of smallest weight that connects to a vertex that
has not yet been visited.
3. Continue until all vertices have been visited.
4. Return to the starting vertex.
Greedy Algorithm
Greedy Algorithm
Greedy Algorithm
Total “cost” or“weight”:
12 + 8 + 12 + 18 + 23 =
73
Comparing Algorithm
Greedy Algorithm Edge-Picking Algorithm

Total cost = 73 Total cost = 74


Exercise
s
Use the edge-picking algorithm to find
the Hamiltonian circuit.
Draw a weighted graph that represents the travel
costs between cities. Use both greedy algorithm
and edge-picking algorithm to find a low-cost
route.
Thank you and
God bless you!!!

You might also like