Undirected Graphs
More Foundations
An undirected graph is a pair of
1. A set of nodes
2. A set of edges (where an edge is a set of two nodes*)
Graphs, Products, & Relations
Friday, September 2, 2011
a
b
c
d
Reading: Sipser 0.2 – beginning of 0.4; Stoughton 1.1.5
CS235 Languages and Automata
Department of Computer Science
Wellesley College
e
({a,b,c,d,e},
{{a,b}, {a,c}, {a,d}, {b,d}, {c,d}, {c,e}})
*This definition does not allow so-called self-edges from
a node to itself. We could extend the definition to allow
self-edges, but we won’t do that here.
Graphs, Products, & Relations
Degree
A Theorem
The degree of a node is the number edges at that node.
a
3-2
b
For every graph G, the sum of the degrees of all the nodes in
G is an even number.
degree(a) = degree(c) = degree(d) = 3
Some easy ones
Some not so easy
degree(b) = 2
c
d
degree(e) = 1
sum = 2 + 2 + 2
= 6
e
sum = 1 + 3 + 3 + 4 + 4 + 2 + (7*1)
= 24
Graphs, Products, & Relations
3-3
Graphs, Products, & Relations
3-4
Patience Grasshopper
Right, so off we go then
Theorem. For every graph G, the sum of the degrees of all
the nodes in G is an even number.
Proof.
Finding proofs takes time.
Consider lots of (small)
examples to gain intuition.
o Come back to it. Let the
unconscious self help you.
o Use simple, clear pictures
and/or text.
o Be concise. Brevity helps you
express high-level ideas
without getting lost in the
detail.
o
o
G is connected to two nodes.
2. Each edge contributes one to the degree of each node
to which it is connected.
3. Therefore each edge contributes two to the sum of the
degrees of all the nodes.
4. Ergo, if G contains e edges, then the sum of the
degrees of all the nodes of G is 2e, which is an even
number.
1. Every edge in
Graphs, Products, & Relations
3-5
A Proof by Construction
Graphs, Products, & Relations
3-6
Paths
A path is a sequence of nodes connected by edges.
A graph is 3-regular iff every node has degree 3.
Theorem. For each even number n greater than 2, there
exists a 3-regular graph with n nodes.
Proof. Let n be an even number greater then 2.
Construct G = (V, E) with n nodes as follows . . .
a
b
a
b
c
d
c
d
One construction
that works for n=8
e
path (a,d,c,e)
Graphs, Products, & Relations
3-7
e
path (a,b,a,d,a,c)
Graphs, Products, & Relations
3-8
Cycles
Connectedness
A cycle is a path beginning and ending at the same node.
A simple cycle repeats no nodes except the first/last.
A graph is connected iff there is a path between every
two nodes.
a
b
a
b
a
b
c
d
c
d
c
d
e
e
simple cycle (a,c,d,a)
e
connected graph
Graphs, Products, & Relations
unconnected graph
3-9
Trees
Graphs, Products, & Relations
3-10
Pairs and Cross Products
A tree is a connected graph without any simple cycles.
(a, b) denotes a pair = an (ordered) sequence of two elements.
• a is the first (or left) element of the pair: first( (a,b) ) = a
One of these is a tree:
• b is the second (or right) element of the pair: second( (a,b) ) = b
For any two sets A and B, A x B = {(a,b) | a ! A and b ! B }.
This is called the cross product or Cartesian product of A and B.
E.g., Suppose Sign = {-,0,+}
T
-
Then Bool x Sign = { (T, -), (F, -),
0
(T, 0), (F, 0),
(T, +), (F, +)
F
}
+
The size of a finite set S is written |S|.
What is |A x B| in terms of |A| and |B|?
Graphs, Products, & Relations
3-11
Graphs, Products, & Relations
3-12
Directed Graphs
Out-Degree and In-Degree
In a directed graph:
An directed graph is a pair of
1. A set of nodes
2. A set of directed edges (where each edge is a
pair of two nodes*)
a
b
c
d
e
A node’s out-degree is the number edges leaving it.
A node’s in-degree is the number of edges entering it.
( {a,b,c,d,e},
{(a,b), (a.c), (a,d), (c,e), (c,d),
(d,b), (d,d), (e,c)} )
*This definition does allow self-edges from a node to itself.
Graphs, Products, & Relations
a
b
c
d
e
out-degree(b) = 0
out-degree(e) = 1
out-degree(c) = out-degree(d) = 2
out-degree(a) = 3
in-degree(a) = 0
in-degree(e) = 1
in-degree(b) = in-degree(c) = 2
in-degree(d) = 3
2-13
Tuples and General Cross Products
Graphs, Products, & Relations
2-14
Characters and Strings
We can take the cross product of any number of sets.
For the time being*, we’ll define
An element of A1 x A2 x … x Ak is called a k-tuple.
Char = {a, b, c, … , A, B, C, .. , 0, 1, 2, … }
For small k, k-tuples have special names:
String = { s | s ! Chark for some k ! Nat}
k
k-tuple
k
k-tuiple
0
unit
5
quintuple, pentuple
The length of a string is the size of its tuple.
Strings are usually written using double-quote notation or
no-quote notation rather than as tuples:
1
singleton
6
sextuple, hextuple
2
pair, duple
7
septuple
3
triple
8
octuple
4
quadruple
9
nonuple
Ak stands for A x A x … x A (k times).
A1 is considered a synonym for A.
A0 is considered a synonym for Unit = {unit} (a 1-element set)!
Graphs, Products, & Relations
tuple
double-quote
no-quote
length
(C, S, 2, 3, 5)
“CS235”
CS235
5
(a)
“a”
a
1
()
“”
"
0
* Later we’ll see that Strings can be parameterized over an alphabet.
3-15
Graphs, Products, & Relations
3-16
Binary Relations
Some Binary Relation Definitions
A binary relation on A and B is any subset of A x B. Examples:
The inverse of a binary relation R on A and B is
the relation R-1 = {(b,a) | b ! B, a ! A, and (a, b) ! R).
E.g. a containsChar-1 “aqua”, 9 isSqrtOf-1 -3
containsChar = {(s, c) | s ! String, c ! Char, c is a char in s}
isSqrtOf = {(i, n) | i ! Int, n ! Nat, i2 = n}
A binary relation R on A is:
• reflexive iff a R a for all a !A.
• symmetric iff x R y implies y R x.
• transitive iff (x R y and y R z) implies x R z.
An equivalence relation is one that’s reflexive, symmetric, and
transitive.
closeTo = {(a, b) | a, b ! Nat and |a – b| # 2}
sameLen = {(s, t) | s, t ! String, length(s) = length(t)}
If R is a binary relation, (a, b) ! R is often abbreviated as
a R b (infix notation) or R(a,b) (prefix notation). E.g.
“aqua” containsChar a or
containsChar(“aqua”, a)
-3 isSqrtOf 9
or
isSqrtOf(-3, 9)
Relation
5 closeTo 3
or
closeTo(5, 3)
= on Int
Graphs, Products, & Relations
equiv. rel.?
sameLen
3-17
Closures of Binary Relations
Suppose R is a binary relation on A.
The reflexive closure RC of R is the smallest superset of R that’s
reflexive: RC = R U {(a, a) | a ! A}.
The transitive closure TC of R is the smallest superset of R that’s
transitive. I.e., it is the smallest relation TC such that (1) R $ TC
and (2) (x, y) ! TC and (y, z) ! TC implies (x, z) ! TC.
The reflexive transitive closure of R is the reflexive closure of
the transitive closure of R.
E.g. Simple = {(0,5), (5, 3), (3, 8)} (A = {0, 3, 5, 8})
isOneLess = {(i, i+1) | i ! Int}
Trans. Clos.
transitive?
closeTo
Relations can be generalized to any number of sets.
Refl. Clos.
symmetric?
< on Int
A binary relation on A is any subset of A x A.
E.g., closeTo on Nat, sameLen on String
Relation
reflexive?
Refl. Trans. Clos,
Simple
isOneLess
Graphs, Products, & Relations
3-19
Graphs, Products, & Relations
3-18
© Copyright 2026 Paperzz