To draw a graph in Mathematica, make a list of the edges you want to include, using arrows to indicate which vertices are connected. If you want directed edges, change the code to DirectedEdgesTrue. You get the arrow by typing a dash - then a > symbol.
You can also produce adjacency matrices automatically, but only if you have used the Graph command. Why? The Graph command creates a list, but the GraphPlot command creates a graphics object. It’s complicated. We will discuss these later in the course.
Notice that in the Adjacency matrix, the vertices are renumbered in the order they appear in your Graph statement. If you want to keep them in the traditional order, be careful of the order in which you define your edges. Compare the above to the next couple of cells. All I did was re-order the red entries, and the graph even looks different!
Including the labels in the matrix can help us decipher what the numbers mean. The command below puts headings on the matrix.
To see how many paths of length 7 exist from vertex 2 to vertex 5, we raise the adjacency matrix to the 7th power and check out the corresponding entry in the resulting matrix.
The heading would help here.
There are 1985 paths of length 7 from vertex 2 to vertex 5!
Here is another example using letters to label the vertices.
Here is a little bit of code to find the diameter of a graph. Do you see why each part is there?