文脈自由文法,CYK法ysuzuki/public/algorithm3/...また、自然言語処理に応用されることもある。 コンパイラにおいて構文解析を行う機構を構文解析器(Parser)
Analysis of Algorithms -...
Transcript of Analysis of Algorithms -...
![Page 1: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/1.jpg)
アルゴリズムの設計と解析
黄 潤和、佐藤 温(TA) 2015.4~
![Page 2: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/2.jpg)
Contents (L11/12/13 – MST algorithm and TSP) • Minimal spanning tree • Prim’s algorithm • Kruskal’s algorithm • Travel salesman problem https://www.cs.usfca.edu/~galles/visualization/Algorithms.html
2
![Page 3: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/3.jpg)
What are spanning trees?
3
![Page 4: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/4.jpg)
Results from BFS and DFS?
Note:
![Page 5: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/5.jpg)
What is a minimal spanning tree?
5
• Weighted spanning tree • Weight of spanning tree = sum of tree edge weights • Any spanning tree whose weight is minimal
Single source shortest path tree
![Page 6: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/6.jpg)
6
![Page 7: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/7.jpg)
Property of MSTs
7
• For any edge: c (e.g. c=(G,H)(5) in blue color) in G but not in T (e.g. in red), there is a simple cycle Y ((H,D), (D,E), (E,I), (I,G)) containing only edge c and edges in spanning tree
• Moreover, weight of c must be greater than or equal to weight of any edge in this cycle.
![Page 8: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/8.jpg)
From SSSP to MST
8
From Dijkstra’s to Prim’s algorithms • Change Dijkstra’s algorithm so the priority of
bridge (fn) is length(f,n) rather than minDistance(f) + length(f,n)
• In other words: - starts with any node - keeps adding smallest edge to
expand its path
![Page 9: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/9.jpg)
Dijkstra’s Algorithm (pseudo code)
9
![Page 10: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/10.jpg)
10
C B
A
E
D
F
0
4 2 8
∞ ∞
4 8
7 1
2 5
2
3 9
C B
A
E
D
F
0
3 2 8
5 11
4 8
7 1
2 5
2
3 9
C B
A
E
D
F
0
3 2 8
5 8
4 8
7 1
2 5
2
3 9
C B
A
E
D
F
0
3 2 7
5 8
4 8
7 1
2 5
2
3 9
C B
A
E
D
F
0
3 2 7
5 8
4 8
7 1
2 5
2
3 9
![Page 11: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/11.jpg)
11
An example
Work in class: Start from B, (1) Draw a SSSP (Single source shortest path) (2) Draw a MST (Minimum spanning tree)?
![Page 12: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/12.jpg)
Dijkstra algorithm from B
2
9
1
6 3
5
4
2 1
1
6
5 2
5
F
A B
C
D
H
G
I
E
2 0
9
7 6
4
8
6
7 4
12
Start from A
A B
Start from B
Results are different.
![Page 13: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/13.jpg)
Prim’s algorithm
13
{ T = φ; U = { }; while (U≠V) { let (u, v) be the lowest cost edge such that u∈U and v∈V - U; T = T ∪{(u, v)} U = U ∪{v} } }
Complexity = O(|E|log(|E|))
http://www.deqnotes.net/acmicpc/prim/ Reference in Japanese
![Page 14: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/14.jpg)
14
1
3
5
6
6
8
4
5
4
∞ ∞
0
∞
∞ ∞ a
b c
d
e
f
2
Work in class (Dijkstra algorithm from a)
![Page 15: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/15.jpg)
15
1
3
5
6
6
8
4
5
4
∞ ∞
0
∞
∞ ∞ a
b c
d
e
f
2
Work in class (Dijkstra algorithm from a)
![Page 16: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/16.jpg)
1
3
5
6
6
8
4
5
4
a
b c
d
e
f
2
Work in class (prim’s algorithm)
![Page 17: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/17.jpg)
![Page 18: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/18.jpg)
18
Kruskal's algorithm (basic part)
(Sort the edges in an increasing order) A:={} while E is not empty do { take an edge (u, v) that is shortest in E and delete it from E if u and v are in different components then add (u, v) to A }
![Page 19: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/19.jpg)
Shortest Path 19
![Page 20: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/20.jpg)
20
![Page 21: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/21.jpg)
21
![Page 22: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/22.jpg)
Kruskal’s v. s. Prim’s algorithms
22
• In Kruskal's algorithm, – The set A is a forest. – The safe edge added to A is always a least-
weight edge in the graph that connects two distinct components.
• In Prim's algorithm, – The set A forms a single tree. – The safe edge added to A is always a least-
weight edge connecting the tree to a vertex not in the tree.
![Page 23: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/23.jpg)
23
Kruskal's algorithm (disjoint set) MST_KRUSKAL(G,w) 1 A:={} 2 for each vertex v in V[G] 3 do MAKE_SET(v) 4 sort the edges of E by non-decreasing weight w 5 for each edge (u,v) in E, in order by non-decreasing weight 6 do if FIND_SET(u) != FIND_SET(v) 7 then A:=A∪{(u,v)} 8 UNION(u,v) 9 return A
Animation of Kruskal’s algorithm http://f.hatena.ne.jp/mickey24/20090614234556
![Page 24: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/24.jpg)
Walk-Through Consider an undirected, weight graph
5
1
A
H B
F
E
D
C
G 3
2
4
6
3 4
3
4 8
4
3
10
![Page 25: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/25.jpg)
Sort the edges by increasing edge weight edge dv (D,E) 1
(D,G) 2
(E,G) 3
(C,D) 3
(G,H) 3
(C,F) 3
(B,C) 4
5
1
A
H B
F
E
D
C
G 3
2
4
6
3 4
3
4 8
4
3
10 edge dv (B,E) 4
(B,F) 4
(B,H) 4
(A,H) 5
(D,F) 6
(A,B) 8
(A,F) 10
![Page 26: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/26.jpg)
Select first |V|–1 edges which do not generate a cycle
edge dv (D,E) 1 √
(D,G) 2
(E,G) 3
(C,D) 3
(G,H) 3
(C,F) 3
(B,C) 4
5
1
A
H B
F
E
D
C
G 3
2
4
6
3 4
3
4 8
4
3
10 edge dv (B,E) 4
(B,F) 4
(B,H) 4
(A,H) 5
(D,F) 6
(A,B) 8
(A,F) 10
![Page 27: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/27.jpg)
Select first |V|–1 edges which do not generate a cycle
edge dv (D,E) 1 √
(D,G) 2 √
(E,G) 3
(C,D) 3
(G,H) 3
(C,F) 3
(B,C) 4
5
1
A
H B
F
E
D
C
G 3
2
4
6
3 4
3
4 8
4
3
10 edge dv (B,E) 4
(B,F) 4
(B,H) 4
(A,H) 5
(D,F) 6
(A,B) 8
(A,F) 10
![Page 28: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/28.jpg)
Select first |V|–1 edges which do not generate a cycle
edge dv (D,E) 1 √
(D,G) 2 √
(E,G) 3 χ (C,D) 3
(G,H) 3
(C,F) 3
(B,C) 4
5
1
A
H B
F
E
D
C
G 3
2
4
6
3 4
3
4 8
4
3
10 edge dv (B,E) 4
(B,F) 4
(B,H) 4
(A,H) 5
(D,F) 6
(A,B) 8
(A,F) 10
Accepting edge (E,G) would create a cycle
![Page 29: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/29.jpg)
Select first |V|–1 edges which do not generate a cycle
edge dv (D,E) 1 √
(D,G) 2 √
(E,G) 3 χ (C,D) 3 √
(G,H) 3
(C,F) 3
(B,C) 4
5
1
A
H B
F
E
D
C
G 3
2
4
6
3 4
3
4 8
4
3
10 edge dv (B,E) 4
(B,F) 4
(B,H) 4
(A,H) 5
(D,F) 6
(A,B) 8
(A,F) 10
![Page 30: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/30.jpg)
Select first |V|–1 edges which do not generate a cycle
edge dv (D,E) 1 √
(D,G) 2 √
(E,G) 3 χ (C,D) 3 √
(G,H) 3 √
(C,F) 3
(B,C) 4
5
1
A
H B
F
E
D
C
G 3
2
4
6
3 4
3
4 8
4
3
10 edge dv (B,E) 4
(B,F) 4
(B,H) 4
(A,H) 5
(D,F) 6
(A,B) 8
(A,F) 10
Work in class: Please continue to finish this algorithm and draw the resulting tree.
![Page 31: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/31.jpg)
Apply Kruskal’s algorithm to find the minimum spanning tree
![Page 32: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/32.jpg)
Minimum Connector Algorithms
Kruskal’s algorithm 1. Select the shortest edge in a
network
2. Select the next shortest edge which does not create a cycle
3. Repeat step 2 until all vertices have been connected
Prim’s algorithm 1. Select any vertex
2. Select the shortest edge
connected to that vertex
3. Select the shortest edge connected to any vertex already connected
4. Repeat step 3 until all vertices have been connected
![Page 33: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/33.jpg)
15/7/7 17時36分 Shortest Path 33
https://www.cs.usfca.edu/~galles/visualization/Algorithms.html
Demonstration
http://weierstrass.is.tokushima-u.ac.jp/ikeda/suuri/dijkstra/Prim.shtml
Algorithms in Java
![Page 34: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/34.jpg)
What is travel salesman problem?
34
TSP:
A Salesman wishes to travel around a given set of cities, and return to the beginning, covering the smallest total distance. Create a TSP Tour around all cities
(1) Return to the beginning
(2) No condition to return to the beginning.
It can still be regarded as a TSP by connecting the beginning city and the end city to a ‘dummy’ city at zero distance
A B
![Page 35: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/35.jpg)
Two classifications of TSP
35
A route returning to the beginning is known as a
Hamiltonian Circuit
A route not returning to the beginning is known as a
Hamiltonian Path
![Page 36: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/36.jpg)
Some cases
36
Printed Circuit Board 2392 cities 1987 Padberg and Rinaldi
USA Towns of 500 or more population 13509 cities 1998 Applegate, Bixby, Chvátal and Cook TSP Tour in USA
![Page 37: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/37.jpg)
37
![Page 38: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/38.jpg)
The smallest total distance?
38
Sweden 24978 Cities 2004 Applegate, Bixby, Chvátal, Cook and Helsgaun
Solutions: (1) Try every possibility? (n-1)!, 24977 possibilities (2) Optimizing Methods take very long time (3) Heuristic Methods may not optimal
![Page 39: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/39.jpg)
The Nearest Neighbor Method (Heuristic) - A Greedy method
39
1. Start Anywhere
2. Go to Nearest Unvisited City
3. Continue until all Cities visited
4. Return to Beginning
![Page 40: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/40.jpg)
40
A 42-City Problem The Nearest Neighbour Method (Starting at City 1)
1
21
20
19
29
7
30 28
31 37
32 36
11
9
34
10
39
38
35
12
33
8
27 26
6 24
25
14
15 23
22
2 13
16
3 17 4
18
42
40
41
5
![Page 41: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/41.jpg)
41
The Nearest Neighbour Method (Starting at City 1)
1
21
20
19
29
7
30 28
31 37
32 36
11
9
34
10
39
38
35
12
33
8
27 26
6 24
25
14
15 23
22
2 13
16
3 17 4
18
42
40
41
5
![Page 42: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/42.jpg)
42
The Nearest Neighbour Method (Starting at City 1) Length 1498
1
21
20
19
29
7
30 28
31 37
32 36
11
9
34
10
39
38
35
12
33
8
27 26
6 24
25
14
15 23
22
2 13
16
3 17 4
18
42
40
41
5
![Page 43: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/43.jpg)
43
29
Remove Crossovers
1
21
20
19
7
30 28
31 37
32 36
11
9
34
10
39
38
35
12
33
8
27 26
6 24
25
14
15 23
22
2 13
16
3 17 4
18
42
40
41
5
![Page 44: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/44.jpg)
44
Remove Crossovers
1
21
20
19
29
7
30 28
31 37
32 36
11
9
34
10
39
38
35
12
33
8
27 26
6 24
25
14
15 23
22
2 13
16
3 17 4
18
42
40
41
5
![Page 45: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/45.jpg)
45
Remove Crossovers Length 1453
1
21
20
19
29
7
30 28
31 37
32 36
11
9
34
10
39
38
35
12
33
8
27 26
6 24
25
14
15 23
22
2 13
16
3 17 4
18
42
40
41
5
![Page 46: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/46.jpg)
46
(1) compute a MST (minimum spanning tree) whose weight is a lower bound on the length of an optimal TSP tour. (2) use MST to build a tour whose cost is no more than twice that of MST's weight as long as the cost function satisfies triangle inequality.
Outline of an APPROX-TSP-TOUR
R. B. Muhammad
![Page 47: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/47.jpg)
47
Operation of APPROX-TSP-TOUR Let root be a in following given set of points (graph)
MST-PRIM Preorder
List vertices visited in preorder walk. L = {a, b, c, h, d, e, f, g}
Hamiltonian cycle optimal TSP tour
R. B. Muhammad
![Page 48: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/48.jpg)
48
Exercises 11 Ex 11.1 Draw MST applying prim’s algorithm, starting from node u
a
c
b f
e
d
![Page 49: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/49.jpg)
49
Exercises 11
EX 11.3 (1) What is a TSP problem? (2) Refer the city connection graph in Fig 1, start from the node A, - to draw a MST - to an optimal TSP tour
EX 11.2 Modify the Dijkstra’s algorithm to Prim’s algorithm.
Fig1. City connection graph
12
![Page 50: Analysis of Algorithms - cis.k.hosei.ac.jpcis.k.hosei.ac.jp/~rhuang/Miccl/Algorithm3/2015-lect11-12-13.pdf · Single source shortest path tree . 6 . ... It can still be regarded as](https://reader034.fdocuments.net/reader034/viewer/2022051800/5abf09b37f8b9a7e418dac92/html5/thumbnails/50.jpg)
50