CSCI 2824 Lecture 29: Graph Theory (Basics)In this lecture, we will study graphs and some very basic properties of graphs. We will conclude by studying the concept of Eulerian tours. Directed GraphsWe have already encountered graphs before when we studied relations. We viewed graphs as ways of picturing relations over sets. Definition: Directed Graphs
A directed graph consists of a finite set of nodes (or vertices) and a set of edges .
We draw a graph by drawing circles to represent each of its vertices and arrows to represent edges. The edge is represented by an arrow from to . The direction of the arrow points from to . The arrows have a direction and therefore the graph is a directed graph. Example-1Take and . Here is how we draw this graph: Example-2Take and . The edge and the edge are called self-loops, since they point from a vertex to itself. Assumption
In the study of graphs, will assume that any graph we look at does not have self loops. Most of the results discussed below applies to graphs without self-loops. Why Study Graphs?Graphs are useful in a variety of situations. Graph models are really common representations of networks (computer networks, social networks, protein networks,…). It is very useful to model a variety of entities as graphs and study their structure:
Undirected GraphsSo far, we have studied directed graphs, which are just representations of relations over finite sets (assume that there are no self-loops). An undirected graph is a special kind of directed graph that occurs when the edge relation is symmetric. Definition: Undirected Graphs
An undirected graph is a set of vertices along with a set of edges such that the relation is symmetric:
As a result, we draw an undirected graph by not drawing placing any arrows on the edges. Edges are simply straight-lines. Alternatively, we could have represented each edge by a double arrow, one in each direction or two sets of arrows. These are all equivalent. Example-1Consider the undirected graph : and . Verify that the relation represented by is indeed symmetric. Here is how we draw this graph: Example-2Take and . Once again, this graph has self loops. But we will silently assume, henceforth, that there are no self-loops. Representing GraphsThere are two ways of representing a graph inside a computer: adjacency list or a adjacency matrix. You should already be aware of adjacency list and matrix representations of graphs from your data-structures class (please email me if you are not). We will not go into these concepts here. Degrees and Degree SequencesIn/Out DegreeLet be a directed graph with vertex set and edge set . The set of incoming edges of a vertex are all those edges whose arrows point into : In-Degree
In-Degree For any vertex , the in-degree of is the number of incoming edges into . Similarly, we can define outgoing edges for a given vertex : Out-Degree
For any vertex , the out-degree of is the number of outgoing edges out of . Note For a undirected graph, the set of incoming edges is the same as the set of out-going edges for any vertex Degree
The degree of a vertex in an undirected graph is the number of (we can say either incoming or outgoing) edges that are incident on . Note that the concepts of in-degree and out-degree coincide with that of degree for an undirected graph. Degree SequencesLet us take an undirected graph without any self-loops. Going through the vertices of the graph, we simply list the degree of each vertex to obtain a sequence of numbers. Let us call it the degree sequence of a graph. The degree sequence is simply a list of numbers, often sorted. Example-1Consider the undirected graph : and .
The degree sequence is . Example-2Here is a graph with degree sequence . Example-3Can you construct a graph with a degree sequence ? It needs to have three vertices and a single edge between and and no edges to . Properties of Degree SequencesGiven a undirected graph without self-loops, what can we say about its degree sequence? Example-1Can there be an undirected graph (no self-loops allowed) with degree sequence ? Answer
There can be no such graph. Let us try to construct such a graph. How many nodes does it need to have? from the degree sequence, we know that it has nodes. Now note that there must be a node with degree according to the given degree sequence. However, every node can have between and edges. Sum of Degree SequenceFor an undirected graph without self-loops, the sum of all the numbers in its degree sequence is exactly twice the number of edges. In other words, let be the vertex set of an undirected graphs with no self-loops and be the edge set. Let us write the degree of a node as . We conclude that Proof
By summing up the degree of each vertex, we are counting all edges that are incident on that vertex. In this summation, therefore each edge in the graph contributes to a value of (one for the degree of and one for the degree of ). Therefore, we conclude that the summation is twice the number of edges. As a consequence, the summation of a degree sequence must be even. ExampleIs it possible to have a graph (no self-loops allowed, remember) with the following degree sequence ? Answer
Answer is no since the sum of the degree sequence is which is an odd number. Degree Sequence and Pigeon Hole PrincipleLet be an undirected graph so that
Proof
The proof is simple application of the pigeon-hole principle. In , every vertex can have a degree between , where is the total number of vertices. This means that there are possible degrees (holes) and possible vertices (pigeons). Therefore two vertices must have the same degree. In/Out degress for directed GraphsFor a directed graph with vertices and edges , we observe that In other words, the sum of in-degrees of each vertex coincided with the sum of out-degrees, both of which equal the number of edges in the graph. This is because, every edge is incoming to exactly one node and outgoing to exactly one node. Therefore summing up all the in-degrees, counts very edge precisely once, when we add up . Similar reasoning applies to out-degrees too. WalkGiven a graph (can be directed or undirected), with vertices and edges , a walk of the graph is a sequence of alternating vertices and edges such that
A walk has to respect the edge direction. In other words, if we go from vertex to vertex in a single step then the edge must be present. This is important for directed graphs and is trivial for undirected graphs. Example-1Take the graph: Here is a walk: Here is another example of a walk: Here is an example of a sequence that is not a walk: There is no edge from to . So our walk cannot go in one step from to . Example-2Take the graph: Here are some walks
PathsA path in a graph is a walk that does not repeat any vertices. The length of a path is the number of edges traversed by the path and one less than the number of vertices traversed. Consider, again, the graph below: Examples of paths include:
Non-examples of paths include:
Eulerian TourRead about the Koenigsberg bridge problem here: Seven Bridges of Koenigsberg. Here is the map of Koenigsberg in Germany where the famous mathematician Leonard Euler lived: The green ovals show the bridges. Question is can we take a tour of each of the bridges:
We can ask the same question on the following graph which represents the topology Is the connection between the original “topology” of the bridges and graphs clear? If so, then the problem can be stated as: Let us “walk” the graph starting from any vertex and traversing any edge that takes us to a neighbouring vertex and so on, such that
Eulerian TourDefinition:Eulerian Tour
An Eulerian tour is a special walk of the graph with the following conditions:
Example-1Does this graph have an Eulerian Tour: Yes, here is a tour: . We started from and ended at . Also note that we have traversed each of the six edges in the graph exactly once. Example-2What about this graph? It does not have a tour. This is the graph, we derived from the Konigsberg bridge problem. Turns out that we cannot have an Eulerian tour here. To see this, let us focus on the vertex labelled .
Theorem
An undirected, connected graph (without self-loops) has an Eulerian tour if and only if every vertex in the graph has an even degree. Since the graph of Konigsberg bridge problem has vertices with odd degree, it cannot have an Eulerian tour. Interestingly, there is an efficient algorithm called Fleury's Algorithm that can be used to construct an Eulerian tour if the given graph has all vertices with even degree. |