Graph Utilities Package >

AdjacencyMatrix

AdjacencyMatrix[g]
gives the SparseArray object representing the graph g.
AdjacencyMatrix[g, n]
gives the SparseArray object representing the graph g, adding additional unconnected vertices, if necessary, to create a graph with n vertices.
  • The graph g can be specified by a rule list, an adjacency matrix, or the Combinatorica representation of a graph.
  • The rows/columns of the SparseArray object correspond to vertices in the order returned by VertexList[g].
Needs["GraphUtilities`"]
The SparseArray representation of a graph specified by a rule list:
In[2]:=
Click for copyable input
Out[2]//MatrixForm=
 
Needs["GraphUtilities`"]
This gives a SparseArray representation of a graph specified by a Combinatorica object:
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]//MatrixForm=
 
Needs["GraphUtilities`"]
This adds an extra row and column to the adjacency matrix, corresponding to unconnected vertices:
In[2]:=
Click for copyable input
In[3]:=
Click for copyable input
Out[3]//MatrixForm=
In[4]:=
Click for copyable input
Out[4]=
© 2008 Wolfram Research, Inc. japanese.gif
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team