Professional Documents
Culture Documents
(a) / x 6 4 z 3 x 9
(b) d c 8 / d 4 7
/ x 6 4 z 3 x 9
/ x 6 4 z (3 x) 9
/ x 6 4 ( z (3 x)) 9
x 6 4 z 3 x / 9
/ ( x 6) 4 ( z (3 x)) 9
/ (( x 6) 4) ( z (3 x)) 9
(( x 6) 4) / ( z (3 x)) 9
((( x 6) 4) / ( z (3 x))) 9
Solution:
d c 8 / d 4 7
((d c) 8) ((d 4) / 7)
d c 8 d 4 7 /
Given the following postfix expressions:
(a) r s 3 r 64 *
(b) y 5 4 x y 3 */ 9
r s 3 r 6 4*
(r s ) 3 r 6 4 *
((r s) 3) r 6 4 *
r s 3 * r 6 4
((r s ) 3) (r 6) 4 *
((r s) 3) ((r 6) * 4)
((r s) 3) ((r 6) * 4)
Solution:
y 5 4 x y 3 */ 9
((( y 5) 4) / ( x * ( y 3))) 9
/ y 5 4* x y 3 9
Shortest Path Problems
• Many problems can be modeled using graphs
with weights assigned to their edges.
Los Angeles
MILEAGE 2451
789
1855
Atlanta 760
833 346
Denver Miami
182
908 1090
Boston 860 834
191
New York
722
Chicago
Shortest path by observation:
observation What is the length of
the shortest path between a and z?
4 2
3
2 1
Ans: a, d, e, z
Dijkstra’s algorithm
• There are several algorithms that find the
shortest path between two vertices.
a: (0, empty)
b: (a,3)
f: (b, 1) {a, b, f, d, g, h} = 8
c: (b, 1)
d: (f, 1)
e: (f, 2)
g: (d, 2)
h: (g, 1)
• Spanning Trees
• Definition: Let G be a simple graph. A
spanning tree of G is a subgraph of G that has a
tree containing every vertex of G.
$1400 Atlanta
• Minimum Spanning Trees
• Definition
• A minimum spanning tree in a connected
weighted graph is a spanning tree that has the
smallest possible sum of the weights of the
edges in G.
• We will examine Prim’s Algorithm and
Kruskal’s Algorithm for finding the
minimum spanning tree.
• Prim’s Algorithm
$1400 Atlanta
Solution
• Choice Edge Cost
• 1 {Chicago, Atlanta} $700
• 2 {Atlanta, New York} $800
• 3 {Chicago, San Francisco} $1200
• 4 {San Francisco, Denver} $ 900
Total: $3600