Download presentation
Presentation is loading. Please wait.
1
Computing an Adjacency Matrix D. J. Foreman
Graphs Computing an Adjacency Matrix D. J. Foreman
2
The Graph & it's Adj1 A To B A B C D E F 1 D C From F E
3
Algorithm for Computing Adj2
If Adj[i,1] && Adj[1,j] == 1 path of length 2 from i to j through node 1 Therefore, If ANY Adj[i,n] && Adj[n,j] == 1, for all n, then a path Length=2 from i to j. Thus, for [i, j] compute: Adj[i,1] && Adj[1,j] || Adj[i,2] && Adj[2,j] || … || Adj[i,n] && Adj[n,j] Repeat for all i and j
4
Computation for 1 pair (A to B)
Let A-F be replaced by 1-6 Find a length 2 path from i=1 to j=2 adj[1,1] && adj[1,2]=0 && 1=>0 adj[1,2] && adj[2,2]=1 && 0=>0 adj[1,3] && adj[3,2]=1 && 1=>1 (13 2) adj[1,4] && adj[4,2]=1 && 0=>0 adj[1,5] && adj[5,2]=0 && 0=>0 adj[1,6] && adj[6,2]=0 && 1=>0 Now "or" these together Adj[1,2] So a path of length 2 from A to B (through C) See the red edges in previous slide
5
Adj[i,1] && Adj[1,j] || Adj[i,2] && Adj[2,j] || … || Adj[i,n] && Adj[n,j]
3 4 5 6 1 2 3 4 5 6 Adj[1] Adj[2]
6
Key Points Adj (by itself) only tells if a path EXISTS
Does NOT tell what the path IS Adj1 * Adj2 Adj3 (path of length 3) Computations describe edges in path Same as regular matrix multiply, but replace * with && + with ||
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.