Download presentation
Presentation is loading. Please wait.
1
Discrete Math 2 Shortest Path Using Matrix
2001 Discrete Math 2 Shortest Path Using Matrix CIS112 February 10, 2007 Daniel L. Silver
2
Overview Previously: Now: In weighted graph . .
Shortest path from one vertex to another Search tree method Now: Same problem Matrix method 2007 Kutztown University
3
Strategy Represent weighted graph as matrix Create search matrix . .
with entries matching nodes expansion node production 2007 Kutztown University
4
Matrix for Weighted Graph
vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 17 16 19 15 24 20 14 21 25 22 2007 Kutztown University
5
Step #0 Create a search matrix Layout same as weighted graph matrix
Entries will hold path information Vertices along path Total cost of path Path info built up step by step 2007 Kutztown University
6
Search Matrix vtx 1 2 3 4 5 6 7 8 9 10 11 12 2007 Kutztown University
7
Step #1 Enter information for first path segment
Initial entry goes in row #7 . . Since #7 is starting vertex 2007 Kutztown University
8
Search Matrix – Step #1 vtx 1 2 3 4 5 6 7 8 9 10 11 12 15 25 2007
Kutztown University
9
Comment Notice similarity to search tree Choose lowest cost entry
Which is in column #3 Corresponds to expanding lowest cost node Next entry goes in row #3 2007 Kutztown University
10
Search Matrix – Step #2 vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 34 15 25
2007 Kutztown University
11
Comment Entries represent path cost Path elements stored implicitly
15+8=23 15+19=34 Path elements stored implicitly Look in row #7 (starting point) Find lowest cost entry (column #3) In corresponding row Find lowest cost entry (column #1) Path is: 7 1 Again, note similarity to search tree 2007 Kutztown University
12
Step #3 Among all leaves . . Find lowest cost entry [7,10]
“Expand” “node” #10 I.e., compute path cost + edge cost Enter into matrix 2007 Kutztown University
13
Search Matrix – Step #3 vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 34 15 25 24
21 2007 Kutztown University
14
Comment No entry is made for starting point – #7
There are two entries in column #8 Correspondence to search tree Two nodes for #8 So we mark higher one as deleted 2007 Kutztown University
15
Search Matrix – Step #3b vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 34 15 25 24
21 2007 Kutztown University
16
Continuing . . Keep choosing “nodes” Keep “expanding” them
Until there are no more to “expand” 2007 Kutztown University
17
Search Matrix – Step #4 vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 34 15 25 24
21 44 43 26 2007 Kutztown University
18
Search Matrix – Step #4b vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 34 15 25 24
21 44 43 26 2007 Kutztown University
19
Comment Reached #12, but not yet finished
Other less costly path possible But not through #4 & #9 Why not? So mark #4 & #9 as dead ends 2007 Kutztown University
20
Search Matrix – Step #4c vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 34x 15 25
24 21 44 43x 26 2007 Kutztown University
21
Step #5 Now expand #1 . . Marking dead ends, if they occur 2007
Kutztown University
22
Search Matrix – Step #5 vtx 1 2 3 4 5 6 7 8 9 10 11 12 46x 28x 23 34x
15 25 24 21 44 43x 26 2007 Kutztown University
23
Comment All entries in row #1 are dead ends
So the column is also a dead end Then the same happens . . with row #3 and column #3 2007 Kutztown University
24
Search Matrix – Step #5b vtx 1 2 3 4 5 6 7 8 9 10 11 12 46x 28x 23x
25 15 24 21 44 43x 26 2007 Kutztown University
25
Step #6 And expand #8 . . Marking dead ends, if they occur 2007
Kutztown University
26
Search Matrix – Step #6 vtx 1 2 3 4 5 6 7 8 9 10 11 12 46x 28x 23x 34x
25 15 35 48x 47 24x 21 44 43x 26 2007 Kutztown University
27
Comment We are finished . . since there are no more nodes to expand
We already have the path cost = 26 How do we get the path? 2007 Kutztown University
28
To Get the Path Start at row 7 Column 10 has an entry . . Go to row 10
giving us 7 10 Go to row 10 Column has 11 an entry . . giving us 7 10 11 Go to row 11 Column has 12 an entry . . giving us 7 10 11 12 2007 Kutztown University
29
Shortest Path from 7 to 12 7 10 11 12 :: 26 2007
Kutztown University
30
Final Comments We see how the 1-1 search tree can be implemented as a matrix We look next at how the 1-many can also 2007 Kutztown University
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.