1 / 6

Graphs

Graphs. Computing an Adjacency Matrix D. J. Foreman. The Graph & it's Adj 1. A. To. B. D. C. From. F. E. Algorithm for Computing Adj 2. 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

archer
Download Presentation

Graphs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Graphs Computing an Adjacency Matrix D. J. Foreman

  2. The Graph & it's Adj1 A To B 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 throughnode 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 (13  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] 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 ||

More Related