Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

14
Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna

Transcript of Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

Page 1: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

Math 170 Project Part 3

By: Guadalupe Esquivel and Marlene Reyna

Page 2: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

10.7 #12Use Dijkstra’s algorithm for the airline route system of Figure 10.7.3 to find the shortest distance from Nashville to Minneapolis. Make a table similar to Table 10.7.1 to show the action of the algorithm.

N= NashvilleS= St. LousLv.= LouisvilleCn.= CincinnatiCh.= ChicagoD= DetroitMw.= MilwaukeeMn.= Minneapolis

Page 3: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

Step 1: Step 2:

Initialize T to be the graph with vertex N= Nashville and no edges. Set L(N)= 0

since the shortest path from N to N has length 0. For the remaining

vertices set them equal to ∞.

Find the vertices adjacent to vertex N and choose the one with the smallest value.

Vertices: Lv, MnL(Lv)= 151L(Mn)= 695Since L(Lv) < L(Mn), Lv is added to V(T).

Length of N

_______Starting point

Ending Point

Page 4: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

Step 3: Step:4Find the vertices adjacent to

vertices N and Lv and choose the one with the smallest value.

Vertices: Mn, S, Cn, Ch, Mw, DL(Mn)= 695L(S)=151+242=393L(Cn)=151+83=234L(Ch)=151+269=420L(Mw)=151+348=499L(D)=151+306=457

Since L(Cn) is less than the rest, Cn is added to V(T).

Find the vertices adjacent to vertices N, Lv, and Cn and choose the one with the smallest value.

Vertices: Mn, S, Ch, D, MwL(Mn)=695L(S)=151+242=393L(Ch)=151+269=420L(Mw)=151+348=499L(D)=151+306=457

Since L(S) is less than the rest, S is added to V(T).

Page 5: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

Step 5: Step 6:Find the vertices adjacent to

vertices N, Lv, Cn, and S and choose the one with the smallest value.

Vertices: Mn, Ch, D, MwL(Mn)=695L(Ch)=151+269=420L(D)=151+306=457L(Mw)=151+348=499

Since L(Ch) is less than the rest, Ch is added to V(T).

Find the vertices adjacent to vertices N,Lv, Cn, S, and Ch and choose the one with the smallest value.

Vertices: Mn, D, MwL(Mw)=151+269+74=494L(Mn)=695L(D)=151+306=457

Since L(D) is less than the rest, D is added to V(T).

Page 6: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

Step 7: Step 8:Find the vertices adjacent to

vertices N, Lv, Cn, S, Ch, and D and choose the one with the smallest value.

Vertices: Mn, MwL(Mw)=151+269+74=494L(Mn)=695

Since L(Mw) is less than the rest, Mw is added to V(T).

Find the vertices adjacent to vertices N, Lv, Cn, S, Ch, D, and Mw and choose the one with the smallest value.

L(Mn)=695

Mn is added to V(T).

Starting point

Ending Point

Page 7: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

Step V(T)The set of vertices of T.

E(T)The set of edges of T.

FThe vertices that are adjacent to at

least 1 vertex.

1 {N} empty set {N}

2 {N} empty set {Lv,Mn}

3 {N,Lv} {{N,Lv}} {Mn,S,Cn,Ch,D,Mw}

4 {N,Lv, Cn} {{N,Lv}, {Lv,Cn}} {Mn, S,Ch,D,Mw}

5 {N,Lv, Cn,S} {{N,Lv}, {Lv,Cn}, {Lv,S}} {Mn,Ch,D,Mw}

6 {N,Lv, Cn,S, Ch} {{N,Lv}, {Lv,Cn}, {Lv,S}, {Lv,Ch}} {Mn,D,Mw}

7 {N,Lv, Cn,S, Ch, D} {{N,Lv}, {Lv,Cn}, {Lv,S}, {Lv,Ch}, {Lv,D}} {Mn,Mw}

8 {N,Lv, Cn,S, Ch, D, Mw} {{N,Lv}, {Lv,Cn}, {Lv,S}, {Lv,Ch}, {Lv,D}, {Ch,Mw}} {Mn}

9 {N,Lv, Cn,S, Ch, D, Mw, Mn}

Page 8: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

Thus, the shortest path from Nashville to Minneapolis has length L(Mn)= 695 miles.

Step L(N)Nashville

L(S)St. Louis

L(Lv)Louisville

L(Cn)Cincinnati

L(Ch)Chicago

L(D)Detroit

L(Mw)Milwaukee

L(Mn)Minneapolis

1 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞2 0 ∞ 151 ∞ ∞ ∞ ∞ 695

3 0 393 151 234 420 457 499 695

4 0 393 151 234 420 457 499 695

5 0 393 151 234 420 457 499 695

6 0 393 151 23 42 457 494 695

7 0 393 151 234 420 457 494 695

8 0 393 151 234 420 457 494 695

Page 9: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

10.7 #14Use Dijkstra’s algorithm to find the shortest path from a to z for the graph. Make a

table similar to Table 10.7.1 to show the action of the algorithm

a

b

f

c

e

z

g

d

1

1

87

1

1

1

20

4

1

Page 10: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

0 a

f ∞

c ∞

e ∞

z ∞

g ∞

d ∞

1

187

1

1

1

20

4

1

Start with vertex a and set its distance to equal to 0 and the rest as ∞

b ∞

0 a

f ∞

c ∞

e ∞

z ∞

g ∞

d ∞

1

187

1

1

1

20

4

1b ∞

Next, choose the vertex with the smallest distance value and remove it from the graph, and calculate the value from that vertex to the adjacent vertices and leave the smaller value

1

4

Page 11: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

0 a

f ∞

c ∞

e

z ∞

g ∞

d ∞

1

187

1

1

1

20

4

1b 1

4

Now choose the vertex with the next smallest value, remove it and calculate the new values for the adjacent vertices

2

8

0 a

f

c

e

z ∞

g 10

d 3

1

187

1

1

1

20

4

1b 1

4

2

8

Repeat until you have chosen vertex z

Page 12: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

0 a

f

c

e

z ∞

g 10

d 3

1

187

1

1

1

20

4

1b 1

4

2

8

0 a

f 8 5

c

e

z

g 10

d 3

1

187

1

1

120

4

1b 1

4

2

23

0 a

f 5

c

e

z

g 10

d 3

1

187

1

1

120

4

1b 1

4

2

6

23

23

0 a

f 5

c

e

z

g

d 3

1

187

1

1

120

4

1b 1

4

2

6

23 7

Page 13: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

0 a

f 5

c

e

z

g

d 3

1

187

1

1

120

4

1b 1

4

2

6

7

The last vertex left is vertex z, the end point. The 7 represents the smallest weighted path there is from vertex a vertex z.

Page 14: Math 170 Project Part 3 By: Guadalupe Esquivel and Marlene Reyna.

Step V(T) E(T) F L(a) L(b) L(c) L(d) L(e) L(f) L(g) L(z)

0 {a} ∅ {a} 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞

1 {a} ∅ {b,e} 0 1 ∞ ∞ 4 ∞ ∞ ∞

2 {a,b} {{a,b}} {c,e,f} 0 1 2 ∞ 4 8 ∞ ∞

3 {a,b,c} {{a,b},{b,c}} {d,e,f,g} 0 1 2 3 4 8 10 ∞

4 {a,b,c,d} {{a,b},{b,c},{c,d}} {e,f,g,z} 0 1 2 3 4 8 10 23

5 {a,b,c,d,e} {{a,b},{b,c},{c,d},{a,e}} {f,g,z} 0 1 2 3 4 5 10 23

6 {a,b,c,d,e,f} {{a,b},{b,c},{c,d},{a,e},{e,f}}

{g,z} 0 1 2 3 4 5 6 23

7 {a,b,c,d,e,f,g} {{a,b},{b,c},{c,d},{a,e},{e,f},{f,g}}

{z} 0 1 2 3 4 5 6 7

8 {a,b,c,d,e,f,g,z} {{a,b},{b,c},{c,d},{a,e},{e,f},{f,g},{g,z}}