-- May 4 In-Class Exercise Thread
There are 4 possible triangles in this graph, enumerated below.
Triangle 1,2,4
d(1,2) + d(2,4) >= d(1,4)
1 + 2 >= 3, inequality holds
d(1,4) + d(4,2) >= d(1,2)
3 + 2 >= 1, inequality holds
d(1,1) + d(4,2) >= d(4,2)
1+ 2 >= 2, inequality holds
Triangle 1,2,3
d(1,2) + d(2,3) >= d(1,3)
1 + 1 >= 2, inequality holds
d(2,3) + d(1, 3) >= d(1,2)
1 + 2 >= 1, inequality holds
d(1,2) + d(1,3) >= d(3,2)
1+ 2 >= 1, inequality holds
Triangle 1,3,4
d(1,3) + d(1,4) >= d(4,3)
2 + 3 >= 1, inequality holds
d(1,3) + d(3, 4) >= d(1,4)
2 + 1 >= 3, inequality holds
d(1,4) + d(3,4) >= d(1,3)
3+ 1 >= 2, inequality holds
Triangle 2,3,4
d(2,3) + d(3,4) >= d(2,4)
1 + 1 >= 2, inequality holds
d(2,4) + d(3, 4) >= d(2,3)
2 + 1 >= 1, inequality holds
d(2,3) + d(2,4) >= d(3,4)
1+ 2 >= 1, inequality holds
Thus, all the edges in the graph obey the triangle inequality.
APPROX-TSP-TOUR:
Pick vertex 1 to be the root.
Q -
1, 0, 0
2, inf, NILL
3, inf, NILL
4, inf, NILL
Q!=0 Loop 1
U = 1,0,0
V = 2 , 0+1 < inf, true
V = 3 , 0+2 < inf, true
V = 4 , 0+3 < inf, true
Q -
2, 1, 1
3, 2, 1
4, 3, 1
Q!=0 Loop 2
U = 2,1,1
V = 3 , 1+1 < 2, true
V = 4 , 1+2 < 3, false
Q -
3, 2, 1
4, 3, 1
Q!=0 Loop 3
U = 3,1,1
V = 4 , 1+2 < 3, false
Q -
4, 3, 1
Q!=0 Loop 4
U = 4,3,1
V = empty set
MST-PRIM returns {1,2,3,4}
Traversal would be 1,2,3,4 if we’re ordering by the size.
Cost of tree traversal for this route is 1 + 1 + 1 + 3 = 6 (the last 3 is to go back to the root)
There are 4 possible triangles in this graph, enumerated below.
Triangle 1,2,4
d(1,2) + d(2,4) >= d(1,4)
1 + 2 >= 3, inequality holds
d(1,4) + d(4,2) >= d(1,2)
3 + 2 >= 1, inequality holds
d(1,1) + d(4,2) >= d(4,2)
1+ 2 >= 2, inequality holds
Triangle 1,2,3
d(1,2) + d(2,3) >= d(1,3)
1 + 1 >= 2, inequality holds
d(2,3) + d(1, 3) >= d(1,2)
1 + 2 >= 1, inequality holds
d(1,2) + d(1,3) >= d(3,2)
1+ 2 >= 1, inequality holds
Triangle 1,3,4
d(1,3) + d(1,4) >= d(4,3)
2 + 3 >= 1, inequality holds
d(1,3) + d(3, 4) >= d(1,4)
2 + 1 >= 3, inequality holds
d(1,4) + d(3,4) >= d(1,3)
3+ 1 >= 2, inequality holds
Triangle 2,3,4
d(2,3) + d(3,4) >= d(2,4)
1 + 1 >= 2, inequality holds
d(2,4) + d(3, 4) >= d(2,3)
2 + 1 >= 1, inequality holds
d(2,3) + d(2,4) >= d(3,4)
1+ 2 >= 1, inequality holds
Thus, all the edges in the graph obey the triangle inequality.
APPROX-TSP-TOUR:
Pick vertex 1 to be the root.
Q -
1, 0, 0
2, inf, NILL
3, inf, NILL
4, inf, NILL
Q!=0 Loop 1
U = 1,0,0
V = 2 , 0+1 < inf, true
V = 3 , 0+2 < inf, true
V = 4 , 0+3 < inf, true
Q -
2, 1, 1
3, 2, 1
4, 3, 1
Q!=0 Loop 2
U = 2,1,1
V = 3 , 1+1 < 2, true
V = 4 , 1+2 < 3, false
Q -
3, 2, 1
4, 3, 1
Q!=0 Loop 3
U = 3,1,1
V = 4 , 1+2 < 3, false
Q -
4, 3, 1
Q!=0 Loop 4
U = 4,3,1
V = empty set
MST-PRIM returns {1,2,3,4}
Traversal would be 1,2,3,4 if we’re ordering by the size.
Cost of tree traversal for this route is 1 + 1 + 1 + 3 = 6 (the last 3 is to go back to the root)