Professional Documents
Culture Documents
Dijkstra's Algorithm: Procedure
Dijkstra's Algorithm: Procedure
a 1 8 2 z
0 3
2
10
c e
Step 0
May 5, 2015 Applied Discrete Mathematics 3
Week 13: Boolean Algebra
Dijkstra’s Algorithm
Example:
b 4
(a) d
5
4 6
a 1 8 2 z
0 3
2
10
c 2
(a) e
Step 1
May 5, 2015 Applied Discrete Mathematics 4
Week 13: Boolean Algebra
Dijkstra’s Algorithm
Example:
b 3
(a,
4 (a) c) d 10 (a, c)
5
4 6
a 1 8 2 z
0 3
2
10
c 2
(a) e 12
(a, c)
Step 2
May 5, 2015 Applied Discrete Mathematics 5
Week 13: Boolean Algebra
Dijkstra’s Algorithm
Example:
b 3
(a,
4 (a) c) d 8
10(a,
(a,c,c)b)
5
4 6
a 1 8 2 z
0 3
2
10
c 2
(a) e 12
(a, c)
Step 3
May 5, 2015 Applied Discrete Mathematics 6
Week 13: Boolean Algebra
Dijkstra’s Algorithm
Example:
b 3
(a,
4 (a) c) d 8
10(a,
(a,c,c)b)
5
4 6
a 1 8 2 z
0 3 14
(a, c, b, d)
2
10
c 2
(a) e 12
10 (a, c)
c, b, d)
Step 4
May 5, 2015 Applied Discrete Mathematics 7
Week 13: Boolean Algebra
Dijkstra’s Algorithm
Example:
b 3
(a,
4 (a) c) d 8
10(a,
(a,c,c)b)
5
4 6
a 1 8 2 z
0 3 14
(a,c,c,b,
b,d,
d)e)
13 (a,
2
10
c 2
(a) e 12
10 (a, c)
c, b, d)
Step 5
May 5, 2015 Applied Discrete Mathematics 8
Week 13: Boolean Algebra
Dijkstra’s Algorithm
Example:
b 3
(a,
4 (a) c) d 8
10(a,
(a,c,c)b)
5
4 6
a 1 8 2 z
0 3 14
(a,c,c,b,
b,d,
d)e)
13 (a,
2
10
c 2
(a) e 12
10 (a, c)
c, b, d)
Step 6
May 5, 2015 Applied Discrete Mathematics 9
Week 13: Boolean Algebra
The Traveling Salesman Problem
The traveling salesman problem is one of the
classical problems in computer science.
A traveling salesman wants to visit a number of cities
and then return to his starting point. Of course he
wants to save time and energy, so he wants to
determine the shortest path for his trip.
We can represent the cities and the distances
between them by a weighted, complete, undirected
graph.
The problem then is to find the circuit of minimum
total weight that visits each vertex exactly once.
May 5, 2015 Applied Discrete Mathematics 10
Week 13: Boolean Algebra
The Traveling Salesman Problem
Example: What path would the traveling salesman
take to visit the following cities?
Toronto
650 550
700
700 Boston
Chicago
200
600
New York
Solution: The shortest path is Boston, New York,
Chicago, Toronto, Boston (2,000 miles).
May 5, 2015 Applied Discrete Mathematics 11
Week 13: Boolean Algebra
Let us talk about…
Trees
May 5, 2015 Applied Discrete Mathematics 12
Week 13: Boolean Algebra
Trees
No. Yes.
Yes. No.
May 5, 2015 Applied Discrete Mathematics 14
Week 13: Boolean Algebra
Trees
Definition: An undirected graph that does not contain
simple circuits and is not necessarily connected is
called a forest.
In general, we use trees to represent hierarchical
structures.
We often designate a particular vertex of a tree as the
root. Since there is a unique path from the root to
each vertex of the graph, we direct each edge away
from the root.
Thus, a tree together with its root produces a directed
graph called a rooted tree.
May 5, 2015 Applied Discrete Mathematics 15
Week 13: Boolean Algebra
Tree Terminology
If v is a vertex in a rooted tree other than the root, the
parent of v is the unique vertex u such that there is a
directed edge from u to v.
When u is the parent of v, v is called the child of u.
Vertices with the same parent are called siblings.
The ancestors of a vertex other than the root are the
vertices in the path from the root to this vertex,
excluding the vertex itself and including the root.
James
Christine Bob
bin spool ls
+ -
y z x y
computer
computer power
computer power
north
computer power
north zoo
computer power
computer power
MIT
BU Tufts
UMass
The spanning trees of this graph connect all libraries
with a minimum number of tunnels.
May 7, 2015 Applied Discrete Mathematics 33
Week 13: Boolean Algebra
Spanning Trees
Example for a spanning tree:
Brandeis Harvard
MIT
BU Tufts
UMass
Since there are 6 libraries, 5 tunnels are sufficient to
connect all of them.
May 7, 2015 Applied Discrete Mathematics 34
Week 13: Boolean Algebra
Spanning Trees
UMass
The least expensive tunnel system costs $20 billion.
May 7, 2015 Applied Discrete Mathematics 36
Week 13: Boolean Algebra
Spanning Trees
Prim’s Algorithm:
• Begin by choosing any edge with smallest weight
and putting it into the spanning tree,
• successively add to the tree edges of minimum
weight that are incident to a vertex already in
the tree and not forming a simple circuit with
those edges already in the tree,
• stop when (n – 1) edges have been added.
Kruskal’s Algorithm:
Kruskal’s algorithm is identical to Prim’s algorithm,
except that it does not demand new edges to be
incident to a vertex already in the tree.
Both algorithms are guaranteed to produce a
minimum spanning tree of a connected weighted
graph.