next up previous
Next: Big-O and notation Up: No Title Previous: Sets, Relations

Relations and Graphs and Matrices

Relations can seem rather abstract things, of dubious utility. One of the things that makes them come alive in computer science is just an alternative way of looking at them (and especially at relations on finite sets). Take a set X and a relation R on it, and identify the members of X with nice dots drawn somewhere on a piece a paper. Then take the relation, and if two members in the set, say (x,y) are related (ie xRy) draw a directed arc from the spot that stands for x to the one that stands for y. By a ``directed arc'' I mean that the line drawn has an arrow on it showing which way it goes, so that there is no possible confusion between the arc (x,y) and the one (y,x). The effect is that the relation has been represented as a graph.

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 xRy 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 $\{1,2,3,4,5\}$.

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 2n2. 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 n2entries in all, and each can be either true or false (2 possible values) so there are 2n2 possibilities in all.


next up previous
Next: Big-O and notation Up: No Title Previous: Sets, Relations
Alan Mycroft
1998-10-05