Graphs and Gates Exam Edition

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

CHAPTER 7

Graph Theory

7.1. Graphs

7.1.1. Graphs. Consider the following examples:

1. A road map, consisting of a number of towns connected with


roads.
2. The representation of a binary relation defined on a given set.
The relation of a given element x to another element y is rep-
resented with an arrow connecting x to y.

The former is an example of (undirected) graph. The latter is an


example of a directed graph or digraph.

a b

d c

Figure 7.1. Undirected Graph.

In general a graph G consists of two things:

1. The vertex set V , whose elements are called vertices, nodes or


points.

2. The edge set E or set of edges connecting pairs of vertices. If


the edges are directed then they are also called directed edges
or arcs. Each edge e ∈ E is associated with a pair of vertices.
82
7.1. GRAPHS 83

a b

d c

Figure 7.2. Directed Graph.

A graph is sometimes represented by the pair (V, E) (we assume V


and E finite).

If the graph is undirected and there is a unique edge e connecting x


and y we may write e = {x, y}, so E can be regarded as set of unordered
pairs. In this context we may also write e = (x, y), understanding that
here (x, y) is not an ordered pair, but the name of an edge.
If the graph is directed and there is a unique edge e pointing from
x to y, then we may write e = (x, y), so E may be regarded as a set
of ordered pairs. If e = (x, y), the vertex x is called origin, source or
initial point of the edge e, and y is called the terminus, terminating
vertex or terminal point.
b
a

d c

Figure 7.3. Graph with parallel edges.

Two vertices connected by an edge are called adjacent. They are


also the endpoints of the edge, and the edge is said to be incident to
each of its endpoints. If the graph is directed, an edge pointing from
vertex x to vertex y is said to be incident from x and incident to y. An
edge connecting a vertex to itself is called a loop. Two edges connecting
the same pair of points (and pointing in the same direction if the graph
is directed) are called parallel or multiple.
7.1. GRAPHS 84

A graph with neither loops nor multiple edges is called a simple


graph. If a graph has multiple edges but no loops then it is called a
multigraph. If it has loops (and possible also multiple edges) then it is
called a pseudograph.
The following table summarizes the graph terminology

Table 7.1.1. Graph Terminology


Type Edges Multiple Edges Allowed? Loops Allowed?
Simple graph indirected no no
Multigraph indirected yes no
Pseudograph indirected yes yes
Directed graph directed no yes
Directed multigraph directed yes yes

The degree of a vertex v, represented deg(v), is the number of edges


that contain it (loops are counted twice). A vertex of degree zero (not
connected to any other vertex) is called isolated. A vertex of degree 1
is called pendant.
The Handshaking Theorem. Let G = (V, E) be an undirected graph
with e edges. Then
X
2e = deg (v) .
v∈V
(This applies even if multiple edges and loops are present.)
In a graph with directed edges, the in-degree of a vertex v, denoted

deg (v), is the number of edges with v as their terminal vertex. The
out-degree of a vertex v, denoted deg+ (v), is the number of edges with
v as their initial vertex. (Note that a loop at a vertex contributes 1 to
both the in-degree and the out-degree of this vertex.)
Number of vertices of odd degree. An undirected graph has an even
number of vertices of odd degree. Proof: Let Ve and Vo respectively
the set of vertices of even degree and the set of vertices of odd degree
in an undirected graph G = (V, E). Then
X X X
2e = deg (v) = deg (v) + deg (v) .
v∈V v∈Ve v∈Vo

Since deg(v) is even for v ∈ Ve , the first sum in the right hand side of
the equality is even. The total sum must be 2e, which is even, so the
second sum must be even too. But its terms are all odd, so there must
be an even number of them.
7.1. GRAPHS 85

Sum of degrees in an directed graph. Let G = (V, E) be a directed


graph. Then X X
deg− (v) = deg+ (v) = |E| .
v∈V v∈V

A weighted graph is a graph whose edges have been labeled with


numbers. The length of a path in a weighted graph is the sum of the
weights of the edges in the path.

a b

6 3
6

d 4 c

Figure 7.4. Weighted Graph.

7.1.2. Special Graphs. Here we examine a few special graphs.

The n-cube: A graph with with 2n vertices labeled 0, 1, . . . , 2n − 1


so that two of them are connected with an edge if their binary repre-
sentation differs in exactly one bit.
110 111

010 011

100 101

000 001

Figure 7.5. 3-cube.

Complete Graph: a simple undirected graph G such that every pair


of distinct vertices in G are connected by an edge. The complete graph
of n vertices is represented Kn (fig. 7.6). A complete directed graph is
a simple directed graph G = (V, E) such that every pair of distinct
vertices in G are connected by exactly one edge—so, for each pair of
distinct vertices, either (x, y) or (y, x) (but not both) is in E.
7.1. GRAPHS 86

e b

d c

Figure 7.6. Complete graph K5 .

Bipartite Graph: a graph G = (V, E) in which V can be partitioned


into two subsets V1 and V2 so that each edge in G connects some vertex
in V1 to some vertex in V2 . A bipartite simple graph is called complete
if each vertex in V1 is connected to each vertex in V2 . If |V1 | = m and
|V2 | = n, the corresponding complete bipartite graph is represented
Km,n (fig. 7.7).
A graph is bipartite iff its vertices can be colored with two colors
so that every edge connects vertices of different color.

Question: Is the n-cube bipartite. Hint: color in red all vertices


whose binary representation has an even number of 1’s, color in blue
the ones with an odd number of 1’s.
p

a
q
b

r
c

Figure 7.7. Complete bipartite graph K3,4 .

Regular Graph: a simple graph whose vertices have all the same
degree. For instance, the n-cube is regular.

7.1.3. Subgraph. Given a graph G = (V, E), a subgraph G0 =


(V , E 0 ) of G is another graph such that V 0 ⊆ V and E 0 ⊆ E. If
0

V 0 = V then G0 is called a spanning subgraph of G.


7.1. GRAPHS 87

Given a subset of vertices U ⊆ V , the subgraph of G induced by


U , denoted hU i, is the graph whose vertex set is U , and its edge set
contains all edges from G connecting vertices in U .
7.2. REPRESENTATIONS OF GRAPHS 88

7.2. Representations of Graphs

7.2.1. Adjacency matrix. The adjacency matrix of a graph is a


matrix with rows and columns labeled by the vertices and such that
its entry in row i, column j, i 6= j, is the number of edges incident on i
and j. For instance the following is the adjacency matrix of the graph
of figure 7.8:1

a b c d
 
a 0 1 0 1
b 1
 0 2 0

c 0 2 0 0
d 1 0 0 1

b
e2
e1
e3
a c

e4 e5
d

Figure 7.8

One of the uses of the adjacency matrix A of a simple graph G is


to compute the number of paths between two vertices, namely entry
(i, j) of An is the number of paths of length n from i to j.

7.2.2. Incidence matrix. The incidence matrix of a graph G is a


matrix with rows labeled by vertices and columns labeled by edges, so
that entry for row v column e is 1 if e is incident on v, and 0 otherwise.
As an example, the following is the incidence matrix of graph of figure
7.8:

1For some authors if i = j then the entry is twice the number of loops incident
on i; so in the example of figure 7.8 entry (d, d) would be 2 instead of 1.
7.2. REPRESENTATIONS OF GRAPHS 89

e1 e2 e3 e4 e5
 
a 1 0 0 1 0
b 1 1 1 0 0
 
c 0 1 1 0 0
d 0 0 0 1 1

7.2.3. Graph Isomorphism. Two graphs G1 = (V1 , E1 ), G2 =


(V2 , E2 ), are called isomorphic if there is a bijection f : V1 → V2 and a
bijection g : E1 → E2 such that an edge e is adjacent to vertices v and
w if and only if g(e) is adjacent to f (v) and f (w) (fig. 7.9).

a1 b1 a2 b2

d2

e1 c2
c1 e2

d1

Figure 7.9. Two isomorphic graphs.

Two graphs are isomorphic if and only if for some ordering of their
vertices their adjacency matrices are equal.

An invariant is a property such that if a graph has it then all graphs


isomorphic to it also have it. Examples of invariants are their number
of vertices, their number of edges, “has a vertex of degree k”, “has a
simple cycle of length l”, etc. It is possible to prove that two graphs are
not isomorphic by showing an invariant property that one has and the
other one does not have. For instance the graphs in figure 7.10 cannot
be isomorphic because one has a vertex of degree 2 and the other one
doesn’t.
7.2. REPRESENTATIONS OF GRAPHS 90

c
3

b e
2 4

a f 1 5

Figure 7.10. Non isomorphic graphs.


7.3. PATHS AND CIRCUITS 91

7.3. Paths and Circuits

7.3.1. Paths. A path from v0 to vn of length n is a sequence of


n+1 vertices (vk ) and n edges (ek ) of the form v0 , e1 , v1 , e2 , v2 , . . . , en , vn ,
where each edge ek connects vk−1 with vk (and points from vk−1 to vk
if the edge is directed). The path may be specified by giving only the
sequence of edges e1 , . . . , en . If there are no multiple edges we can
specify the path by giving only the vertices: v0 , v1 , . . . , vn . The path
is a circuit (or cycle) if it begins and ends at the same vertex, i.e.,
v0 = vn , and has lenght greater than zero. A path or circuit is simple
if it does not contain the same edge twice.

7.3.2. Connected Graphs. A graph G is called connected if there


is a path between any two distinct vertices of G. Otherwise the graph
is called disconnected. A directed graph is connected if its associated
undirected graph (obtained by ignoring the directions of the edges) is
connected. A directed graph is strongly connected if for every pair of
distict points u, v, there is a path from u to v and there is a path
from v to u. A connected component of G is any connected subgraph
G0 = (V 0 , E 0 ) of G = (V, E) such that there is not edge (in G) from a
vertex in V to a vertex in V − V 0 . Given a vertex in G, the component
of G containing v is the subgraph G0 of G consisting of all edges and
vertices of g contained in some path beginning at v.

7.3.3. The Seven Bridges of Königsberg. This is a classical


problem that started the discipline today called graph theory.

During the eighteenth century the city of Königsberg (in East Prus-
sia)1 was divided into four sections, including the island of Kneiphop,
by the Pregel river. Seven bridges connected the regions, as shown in
figure 7.11. It was said that residents spent their Sunday walks trying
to find a way to walk about the city so as to cross each bridge exactly
once and then return to the starting point. The first person to solve
the problem (in the negative) was the Swiss mathematician Leonhard
Euler in 1736. He represented the sections of the city and the seven
bridges by the graph of figure 7.12, and proved that it is impossible to
find a path in it that transverses every edge of the graph exactly once.
In the next section we study why this is so.

1The city is currently called Kaliningrad and is part of the Russian republic.
7.3. PATHS AND CIRCUITS 92

Figure 7.11. The Seven Bridges of Königsberg.

Figure 7.12. Graph for the Seven Bridges of Königsberg.

7.3.4. Euler paths and circuits. Let G = (V, E) be a graph


with no isolated vertices. An Euler path in G is a simple path that
transverses every edge of the graph exactly once. Analogously, an
Euler circuit in G is a simple circuit that transverses every edge of the
graph exactly once.

Existence of Euler Paths and Circuits. The graphs that have an


Euler path can be characterized by looking at the degree of their ver-
tices. Recall that the degree of a vertex v, represented deg(v), is the
number of edges that contain v (loops are counted twice). An even
vertex is a vertex with even degree; an odd vertex is a vertex with odd
degree. The sum of the degrees of all vertices in a graph equals twice
its number of edges, so it is an even number. As a consequence, the
number of odd vertices in a graph is always even.

Let G be a connected multigraph. Then G contains an Euler circuit


if and only if G its vertices have even degree. Also, G contains an Euler
path from vertex a to vertex b (6= a) if and only if a and b have odd
degree, and all its other vertices have even degree.
CHAPTER 9

Boolean Algebras

9.1. Combinatorial Circuits

9.1.1. Introduction. At their lowest level digital computers han-


dle only binary signals, represented with the symbols 0 and 1. The
most elementary circuits that combine those signals are called gates.
Figure 9.1 shows three gates: OR, AND and NOT.

x1
OR GATE x1 + x2
x2

x1
AND GATE x1 x2
x2

NOT GATE x x

Figure 9.1. Gates.

Their outputs can be expressed as a function of their inputs by the


following logic tables:

x1 x2 x1 + x2
1 1 1
1 0 1
0 1 1
0 0 0
OR GATE
122
9.1. COMBINATORIAL CIRCUITS 123

x1 x2 x1 · x2
1 1 1
1 0 0
0 1 0
0 0 0
AND GATE

x x
1 0
0 1
NOT GATE

These are examples of combinatorial circuits. A combinatorial cir-


cuit is a circuit whose output is uniquely defined by its inputs. They
do not have memory, previous inputs do not affect their outputs. Some
combinations of gates can be used to make more complicated combi-
natorial circuits. For instance figure 9.2 is combinatorial circuit with
the logic table shown below, representing the values of the Boolean
expression y = (x1 + x2 ) · x3 .

x1

x2 y

x3

Figure 9.2. A combinatorial circuit.

x1 x2 x3 y = (x1 + x2 ) · x3
1 1 1 0
1 1 0 1
1 0 1 0
1 0 0 1
0 1 1 0
0 1 0 1
0 0 1 1
0 0 0 1

However the circuit in figure 9.3 is not a combinatorial circuit. If


x1 = 1 and x2 = 0 then y can be 0 or 1. Assume that at a given time
y = 0. If we input a signal x2 = 1, the output becomes y = 1, and
9.1. COMBINATORIAL CIRCUITS 124

stays so even after x2 goes back to its original value 0. That way we
can store a bit. We can “delete” it by switching input x1 to 0.

x1

x2

Figure 9.3. Not a combinatorial circuit.

9.1.2. Properties of Combinatorial Circuits. Here Z2 = {0, 1}


represents the set of signals handled by combinatorial circuits, and the
operations performed on those signals by AND, OR and NOT gates are
represented by the symbols ·, + and respectively. Then their prop-
erties are the following (a, b, c are elements of Z2 , i.e., each represents
either 0 or 1):

1. Associative
(a + b) + c = a + (b + c)
(a · b) · c = a · (b · c)
2. Commutative
a+b=b+a
a·b=b·a

3. Distributive
a · (b + c) = (a · b) + (a · c)
a + (b · c) = (a + b) · (a + c)

4. Identity
a+0=a
a·1=a

5. Complement
a+a=1
a·a=0

A system satisfying those properties is called a Boolean algebra.

Two Boolean expressions are defined to be equal is they have the


same values for all possible assignments of values to their literals. Ex-
ample: x + y = x · y, as shown in the following table:
9.1. COMBINATORIAL CIRCUITS 125

x y x+y x·y
1 1 0 0
1 0 0 0
0 1 0 0
0 0 1 1

9.1.3. Abstract Boolean Algebras. Here we deal with general


Boolean algebras; combinatorial circuits are an example, but there are
others.

A Boolean algebra B = (S, ∨, ∧, , 0, 1) is a set S containing two


distinguished elements 0 and 1, two binary operators ∨ and ∧ on S,
and a unary operator on S, satisfying the following properties (x, y,
z are elements of S):

1. Associative
(x ∨ y) ∨ z = x ∨ (y ∨ z)
(x ∧ y) ∨ z = x ∧ (y ∧ z)
2. Commutative
x∨y =y∨x
x∧y =y∧x

3. Distributive
x ∧ (y ∨ z) = (x ∧ y) ∨ (x ∧ z)
x ∨ (y ∧ z) = (x ∨ y) ∧ (x ∨ z)

4. Identity
x∨0=x
x∧1=x

5. Complement
x∨x=1
x∧x=0

Example: (Z2 , +, ·, , 0, 1) is a Boolean algebra.


Example: If U is a universal set and P(U )= the power set of S (col-
lection of subsets of S) then (P(U ), ∪, ∩, , ∅, U ). is a Boolean algebra.

You might also like