The adjacency matrix is the n by n matrix (where n is the number of vertices in graph/digraph G) with rows and columns indexed by the vertices of G. Entry A_(u,v) is 1 if and only if {u,v} is an edge of G and 0 otherwise. It is easy to observe that if we just use a simple graph G, then its adjacency matrix must be symmetric, but if we use a digraph, then it is not necessarily symmetric.
i1 : D = digraph({{1,2},{2,3},{3,4},{4,3}},EntryMode=>"edges"); |
i2 : adjacencyMatrix D o2 = | 0 1 0 0 | | 0 0 1 0 | | 0 0 0 1 | | 0 0 1 0 | 4 4 o2 : Matrix ZZ <--- ZZ |
i3 : G = graph({1,2,3,4}, {{1,2},{2,3},{3,4},{4,3}}) o3 = Graph{1 => {2} } 2 => {1, 3} 3 => {2, 4} 4 => {3} o3 : Graph |
i4 : adjacencyMatrix G o4 = | 0 1 0 0 | | 1 0 1 0 | | 0 1 0 1 | | 0 0 1 0 | 4 4 o4 : Matrix ZZ <--- ZZ |
The object adjacencyMatrix is a method function.