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 Graphs

We 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 G consists of a finite set of nodes (or vertices) V and a set of edges E subseteq V times V.

  • Each edge is a tuple (u,v) where u,v in V are vertices of the graph.

  • The set of edges E is a relation over V.

We draw a graph G by drawing circles to represent each of its vertices and arrows to represent edges. The edge (u,v) is represented by an arrow from u to v. The direction of the arrow points from u to v. The arrows have a direction and therefore the graph is a directed graph.

Example-1

Take V={a,b,c,d} and E = {(a,b), (b,c), (a,c), (a,d), (d,b), (d,a), (d,c) }. Here is how we draw this graph:

100

Example-2

Take V={hello, world, discrete, math} and E = {( hello, hello), (hello, world), (hello, discrete), (hello, math), (math, math), (math, hello), (math, world) }.

200

The edge (hello,hello) and the edge (math, math) 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:

  • Eg., set of nodes = people on facebook and edges = friendship. Prof. Clauset's group at CU Boulder specializes on such graphs, among many others.

  • Eg., set of nodes = proteins and edges = protein-protein interactions. Our bioinformatics research group (Prof. Goldberg) looks at such interactions in graphs.

  • Eg., set of nodes = web pages and edges = links between pages.

Undirected Graphs

So 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 G is a set of vertices V along with a set of edges E subseteq V times V such that the relation E is symmetric:

  • Whenever the edge (u,v) exists in an undirected graph then so does the edge (v,u).

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-1

Consider the undirected graph G: V={a,b,c,d} and E = {(a,b), (b,a), (b,c), (c,b), (a,c), (c,a),(a,d),(d,a), (d,b), (b,d), (d,c),(c,d) }. Verify that the relation represented by E is indeed symmetric. Here is how we draw this graph:

100

Example-2

Take V={hello, world, discrete, math} and E = { (hello, world), (world,hello), (hello, discrete), (discrete, hello), (hello, math), (math,hello), (math, world), (world,math) }.

150

Once again, this graph has self loops. But we will silently assume, henceforth, that there are no self-loops.

Representing Graphs

There 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 Sequences

In/Out Degree

Let G be a directed graph with vertex set V and edge set E.

The set of incoming edges of a vertex v are all those edges whose arrows point into v:

 mbox{incoming}(v) = { (u,v) | (u,v) in E } ,.

In-Degree

In-Degree For any vertex v in V, the in-degree of v is the number of incoming edges into v.

Similarly, we can define outgoing edges for a given vertex v:

 mbox{outgoing}(x) = { (x,y) | (x,y) in E } ,.

Out-Degree

For any vertex v in V, the out-degree of v is the number of outgoing edges out of v.

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 v in an undirected graph is the number of (we can say either incoming or outgoing) edges that are incident on v.

Note that the concepts of in-degree and out-degree coincide with that of degree for an undirected graph.

Degree Sequences

Let us take an undirected graph G 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-1

Consider the undirected graph G: V={a,b,c,d} and E = {(a,b), (b,a), (b,c), (c,b), (a,c), (c,a),(a,d),(d,a), (d,b), (b,d), (d,c),(c,d) }.

150
Node Degree
a 3
b 3
c 3
d 3

The degree sequence is 3,3,3,3.

Example-2

Here is a graph with degree sequence 1,2,2,3.

100

Example-3

Can you construct a graph with a degree sequence 0,1,1?

It needs to have three vertices a,b,c and a single edge between b and c and no edges to a.

 textcircled{a} quad textcircled{b} - textcircled{c}

Properties of Degree Sequences

Given a undirected graph G without self-loops, what can we say about its degree sequence?

Example-1

Can there be an undirected graph (no self-loops allowed) with degree sequence 1,2,3,4,5?

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 5 nodes. Now note that there must be a node with degree 5 according to the given degree sequence. However, every node can have between 0 and 4 edges.

Sum of Degree Sequence

For an undirected graph G without self-loops, the sum of all the numbers in its degree sequence is exactly twice the number of edges.

In other words, let V = {v_1,ldots,v_n} be the vertex set of an undirected graphs with no self-loops and E be the edge set. Let us write the degree of a node v_i as mathsf{degree}(v_i). We conclude that

 sum_{v in V} mathsf{degree}(v) = 2 |E|

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 (u,v) in the graph contributes to a value of 2 (one for the degree of u and one for the degree of v). Therefore, we conclude that the summation is twice the number of edges.

As a consequence, the summation of a degree sequence must be even.

Example

Is it possible to have a graph (no self-loops allowed, remember) with the following degree sequence 1,1,1,2,2,4,4?

Answer

Answer is no since the sum of the degree sequence is 3 + 4 + 8 = 15 which is an odd number.

Degree Sequence and Pigeon Hole Principle

Let G be an undirected graph so that

  • G has no self-loops

  • every vertex of G has some edge that incident on it (there are no degree 0 vertices). At least two vertices in the graph must have the same degree.

Proof

The proof is simple application of the pigeon-hole principle. In G, every vertex can have a degree between 1,ldots,(n-1), where n = |V| is the total number of vertices. This means that there are n-1 possible degrees (holes) and n possible vertices (pigeons). Therefore two vertices must have the same degree.

In/Out degress for directed Graphs

For a directed graph G with vertices V={v_1,ldots,v_n} and edges E subseteq V times V, we observe that

 sum_{v in V} mathsf{incoming}(v) = sum_{v in V} mathsf{outgoing}(v) = |E|

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 (u,v) precisely once, when we add up mathsf{incoming}(v). Similar reasoning applies to out-degrees too.

Walk

Given a graph G (can be directed or undirected), with vertices V and edges E, a walk of the graph is a sequence of alternating vertices and edges such that

  • We can start our walk at any vertex and end at any vertex.

  • A single step of the walk takes an outgoing edge from current vertex to visit a neighbouring vertex.

A walk has to respect the edge direction. In other words, if we go from vertex u to vertex v in a single step then the edge (u,v) must be present. This is important for directed graphs and is trivial for undirected graphs.

Example-1

Take the graph:

150

Here is a walk:

 hello rightarrow hello rightarrow math rightarrow hello rightarrow discrete

Here is another example of a walk:

 hello rightarrow hello rightarrow math rightarrow math

Here is an example of a sequence that is not a walk:

 hello rightarrow discrete rightarrow world rightarrow world

There is no edge from discrete to world. So our walk cannot go in one step from discrete to world.

Example-2

Take the graph:

150

Here are some walks

  • a (just start and stop at a).

  • a rightarrow d rightarrow b rightarrow c rightarrow d.

  • a rightarrow c rightarrow b rightarrow d rightarrow a.

Paths

A 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:

150

Examples of paths include:

  • a rightarrow d rightarrow b rightarrow c (it is a path of length 3)

  • a rightarrow b (it is a path of length 1)

  • a (trivially it is a path of length 0)

Non-examples of paths include:

  •  a  rightarrow d rightarrow a rightarrow b. This is a walk but not a path since it repeats the vertex a.

Eulerian Tour

Read 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:

300

The green ovals show the bridges. Question is can we take a tour of each of the bridges:

  • starting anywhere we like as long as we return to our starting point

  • traversing each of the bridges exactly once.

We can ask the same question on the following graph which represents the topology

150150150

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

  • Each edge can be traversed at least once in either direction.

  • We have to end the walk at the same vertex where we began.

Eulerian Tour

Definition:Eulerian Tour

An Eulerian tour is a special walk of the graph with the following conditions:

  • The walk starts and stops at the same vertex

  • Every edge in the graph is traversed exactly once during the tour.

Example-1

Does this graph have an Eulerian Tour:

300

Yes, here is a tour: 2 rightarrow 1 rightarrow 2 rightarrow 3 rightarrow 4 rightarrow 2.

We started from 2 and ended at 2. Also note that we have traversed each of the six edges in the graph exactly once.

Example-2

What about this graph?

300

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 c.

  • c has three edges incident on it.

  • The walk must traverse each of the 3 edges. Let us assume that the walk does not start at c. If it does, we can simply do the following reasoning about the node b, instead.

  • We must enter c by one of the edges for the first time and leave it by another edge. This leaves one edge untraversed.

  • But we can only use the untraversed edge to enter c and thence we will be stuck (since all the other edges are traversed).

Theorem

An undirected, connected graph G (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 a,b 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.