Now set up a square table, with one row for each possible *x* or *y* and
one column for each. Fill in the cell at position (*x*,*y*) with
a true or false marker that indicates whether *x*R*y* holds. The
relation has been represented as a matrix. And in passing we have shown
that any graph can be represented as a matrix, and any matrix that
has just boolean values can be interpreted as a graph. To give yourself
concrete example, try drawing the graphs and matrices for the relations =and < as they apply to the set
.

Now I can come back to the transitive closure of a relation. A typical application is to start with a set consisting of cities, and a relation which is true if there is a direct non-stop rail link between the two cities involved. Then the transitive closure of this relation will indicate whether there is any way of travelling by rail between two places, ignoring the original requirements that the journey be direct and non-stop. In terms of graph operations this is now probably reasonably easy to visualise.

Interpreted in this new image, a reflexive closure just adds little loops to each vertex in the graph so you can do a small round trip and get back to where you started. Note the difference between being somewhere and being able to get somewhere by taking a single step of a journey--adding the loops does make a real difference.

A symmetric closure extends the rail network
so that if it is possible to go from *A* to *B* then it is also possible
to get back from *B* to *A*.

There are a great many natural and important problems that are naturally thought of in terms of graphs--and so relations can provide some mathematical notation and underpinning while sometimes boolean matrices may be a useful concrete representation for computers to use. Sample problems include:

- 1.
- Is the graph connected (ie each vertex can be reached from any other)? If not, how many pieces does it fall into?
- 2.
- What is the longest path you can take through the graph without visiting any vertex more than once. What is the longest path that does not traverse any edge more than once?
- 3.
- Given a connected graph, is there any vertex which if removed would leave it not connected? This is important for communication networks, in that such a vertex would be critical for the reliability of the whole net.
- 4.
- How many colours are needed to colour each vertex of the graph so that vertices that are joined by an edge have different colours?
- 5.
- Within the graph, where is the largest subset of vertices that are all mutually directly connected.
- 6.
- Given two graphs are they really the same shape, only differing in the way they happen to have been described?

A special sort of graph (and hence relation) has all arcs starting in one
subset of its vertices (call that subset *A*), and ending in another (*B*),
and only one arc issuing from any one vertex.
This can be seen as a way of representing a function from the set *A* to
*B*.

Looking at relations and functions as graphs is probably the easiest
way of working out how many of them there are. For instance for
a set *X* with size *n* the number of
relations possible is 2^{n2}. These range from the vacuuous one where
the relation is never true to the almost equally silly one where it is
always satisfied. See this by observing that each relation on *X* can
be seen as an *n* by *n* matrix with boolean entries, so there are *n*^{2}entries in all, and each can be either true or false (2 possible values)
so there are 2^{n2} possibilities in all.