Section1.3Basics

Sage comes with many graphs preinstalled. Thus the command

sets $K$ equal to the complete graph on 5 vertices. Now K.show() produces a drawing of the graph in a separate window.

The command

displays the vertices of our graph and

displays the edges. To avoid the empty labels, try

The command K.degree() produces a list of the vertex degrees, while K.deg(u) gives the degree of the vertex $u$. Further K[i] returns the neighbors of $i$ in $K$. If your graph is regular (K.is_regular() returns True) then its valency is given by

There are many built-in graphs in Sage. Thus:

gives us the cycle on 8 vertices. To get the list of possible graphs, type graphs. at the prompt, followed by a tab. (That's 8 keypresses—6 letters, a period and a tab.)

There are many graph operations we can use. We can get the complement of our cycle by

and its line graph by

Of course a cycle is isomorphic to its line graph, which we can verify:

Another way to verify that $LC$ is the cycle $C_8$ is to verify that it is connected

and that it is regular of degree two

Sage supplies the Petersen graph

and we can verify this is correct by computing its diameter, girth and the number of vertices since these three properties characterize the graph.

In practice it is very important to check that any graph you construct is the one you wanted. It may be hard to prove that your graph is correct, but simple checks can still be useful. One common source of error is an incomplete understanding of the commands you use. For example

produces a graph on three vertices!

I should have used K2.disjoint_union(K3).