Königsberg’s Bridge Problem
Is it possible to walk around all bridges once and only once, and return to the starting point? (circuit)
What about a “path” which visits all bridges? Modeling the problem in terms of graphs: Equivalent problem: Can you draw this graph without lifting the pen from paper and repeating any lines?
1
Euler Paths and Circuits
An Euler path is a path that passing every edge (i.e., line) in the graph exactly once. An Euler circuit is a Euler path that starts and ends at the same vertex (i.e., circle). Example:
How to determine whether a graph has an Euler path/circuit?
2
Existence of Euler Paths/Circuits
Degree of a vertex = number of edges incident to that vertex
Degree-1 vertex: Euler circuit? Degree-3? Degree-4?
?
?
Observation: Vertices must have even degree for an Euler circuit. Is the condition sufficient?
3
Proof of Euler Circuit
Theorem: A graph has an Euler circuit iff all vertices have even degrees. Proof: Only if (=>) part (necessary condition):
Each time an Euler circuit passes through a vertex u it “consumes” two edges incident with u (one “in” and one “out”). An Euler circuit covers all edges of G exactly once. If a vertex u is visited by the circuit x times, deg(u) = 2x.
4
Sufficient Condition for Euler Circuit
If (<=) part: (If G is a graph with all vertices of even degree, then G contains an Euler circuit) The proof is by construction. pick any arbitrary vertex u, follow any edge from u to another vertex v, again reach at another vertex through another unvisited edge from v (this is possible because the number of incident edges at any vertex is even)
u u
b
v v
•
The path will continue until it reaches vertex u again.
5
Proof for the Sufficient Condition
• It is done if the closed path covers the whole graph, otherwise repeat the previous procedure at some vertex u’ in the closed path.
•
A longer closed path will be formed by merging these closed paths by inserting the new closed path to the old closed path at vertex u’.
u u’
•
This process will repeat until all edges are exhausted.
6
Word Puzzle
Given these words: CAR, CUB, DIM, HEN, HUT, MOB, RED, SAW, SON, WIT. The task is to arrange these words in a closed chain such that any two adjacent words must share a common letter. The right list is correct except RED and SON. This can be reduced to a graph problem. V = set of words Two words are connected by an edge if they share a common letter. The problem is to find a circuit which visits every vertex exactly once. (Hamiltonian Circuit)
7
Word Puzzle
Let this list of words HEN, HUT, WIT, SAW, CAR, CUB, MOB, DIM, RED, SON. be replaced HUT and SON by HOT and SUN. Then we can arrange the words in a closed chain, i.e, there exists a Hamiltonian circuit for the graph on the right.
8
Hamiltonian Paths and Circuits
A Hamiltonian path is a path containing every vertex once and only once. A Hamiltonian circuit is a circuit containing every vertex once and only once. Example: (round-the-world puzzle)
9
Mathematically, a graph is a pair G = (V, E) where V is a set of 'circle' called vertices, and E ⊆ V x V is a set of 'line' connecting two vertices.
v1 v4
Example: G = (V, E) where V = { v1, v2, v3, v4 } and E = {(v1, v3), (v2, v3), (v1, v4), (v2, v4) }
v2
v3
10
Complete graphs
A graph G = (V, E) is said to be complete if it has all the possible edges, i.e., E = V x V. Example
v1 v4
K4
v2 v3
For any integer n > 0, we use Kn to denote the complete graph with n vertices.
11
Bipartite graph
Consider a set of boys and girls and their possible relationships:
A graph is bipartite if the vertices V can be partitioned into two disjoint sets V1, V2 such that every edge connects a vertex in V1 to a vertex in V2
i.e. no edge within V1, no edge within V2 e.g. set of boys = V1, set of girls = V2
Number of edges ≤ |V1| |V2| .
12
Bipartite Graphs
Are these graphs bipartite?
A graph is bipartite iff the graph contains no odd cycles. A complete bipartite graph Km,n is a bipartite graph with all possible edges between a set of m vertices and a set of n vertices e.g. K3,4
13
Graph Operations
A graph H = (V’, E’) is a subgraph of G = (V, E) if V’⊆V, E’ ⊆ E. We say that it is a spanning subgraph of G if V’=V.
G
H
14
Graph Operations
The complement of G, denoted G, is the subgraph of Kn consisting of all the edges that are not in G. V’=V
G
G
15
Graph Operations
The union of two graphs G1 = (V1, E1) and G2 = (V2, E2) is G1 ∪ G2 = (V1 ∪ V2, E1 ∪ E2)
a c G1 b d c e G2 a b d c e a b d G1 ∪ G2
16
Paths
A path of length n from u to v in a graph G is a sequence of edges e1, e2, … en, such that e1 = (u, x1), e2 = (x1, x2), …, en = (xn-1, v). Example:
17
Circuits
A circuit (or cycle) is a path that starts and ends at the same vertex. A path or circuit is simple if it does not contain the same edge more than once If there is a path between u and v, then there is a simple path between u and v: u → a → b → c → d → e → f → a → b → v is a path
e f u a b d c v
u → a → b → v is a simple path
18
Graph Connectivity
A graph is connected if there is a path between any two vertices. If a graph is not connected, each connected subgraph is called a connected component of the graph. Example: (3 connected components)
19
Hamiltonian Circuit and Traveling Salesman Problem
Hamiltonian circuit: Given a graph, find a circuit containing every vertex once and only once.
a
Traveling Salesman Problem (TSP): Given a weighted, complete graph, find a circuit of minimum total weight, which visits each vertex exactly once. weight (a c b d e) = 21
7 e 1 4 d 6 0 9 2
8 b 3 5
c
We can find the optimal TSP circuit by exhaustion, i.e., to find the weights of all the (n-1)! Hamiltonian circuits
20
Hamiltonian Circuit and Traveling Salesman Problem
HC problem can be reduced to TSP (i.e., TSP is more difficult) The graph G(V, E) for the HC problem will be transformed to a weighted graph G’(V’, E’) for the TSP. We try to solve the HC problem by solving the TSP problem. HC: Input = G(V, E); Output = “yes” with HC / “no”, TSP: Input = weighted complete graph G’(V’, E’) Output = minimum-weighted circuit
Input for HC, G(V,E) Transform to weighted graph Transform to Output for HC Weighted graph Min-weighed circuit
Algorithm to solve TSP
Output for HC, Yes/no
21
Hamiltonian Circuit and Traveling Salesman Problem
Input for HC: a undirected graph Input for TSP: a weighted complete graph G’ is a complete graph with V’ = V and w(e) = 1 if e is in E w(e) = M if e is not in E, where M is a constant > |V| Output for TSP: minimum weight circuit Output for HC: “yes” iff G’ has a TSP circuit of weight |V|, i.e., only those edges in G are used. G
G’
1 1 1 M 1 M M
M
1
1
22
Directed graph
A directed graph is just a graph in which we assign a direction to every edge in the graph.
Undirected graph
A directed graph
23
Hamiltonian path for complete directed graphs
Show that a complete directed graph always has a Hamiltonian path. For example, n = 5
24
Proof of the Existence of HP
Theorem: Any complete directed graph has a Hamiltonian path. Proof: By induction on the number of vertices, n. v1 v2 Basis: n = 2, it is true trivially Inductive Step: v6 v7 v3 Assume it is true for n – 1 v2 v5 There exists a HP (v1, v2, …, vn–1) for the directed complete graph v4 vn of n – 1 vertices. v1 vn-1 There are directed edges joining vn-3 vn to {v1, v2, …, vn–1} vn-2 Want to prove that it is true for n.
25
Induction Step on the Existence Proof
Inductive Step: Assume it is true for n – 1 There exists a HP (v1, v2, …, vn–1) for the directed complete graph of n – 1 vertices. v2 There are directed edges joining vn to {v1, v2, …, vn–1}
If vn → v1, then vn v1, v2, …, vn–1 (done) If v1 → vn and vn → v2, then v1 vn v2 …vn–1 (done) If v1 → vn, v2 → vn and vn → v3, then v1 v2 vn v3 …vn–1 (done) If {v1 , v2 , v3} → vn and vn → v4, then v1 v2 v3 vn v4 …vn–1 (done) If {v1 , v2 , …, vk –1} → vn and vn → vk, then v1 … vk –1 vn vk …vn–1 (done) If {v1 , v2 , …, vn –2} → vn and vn → vn-1, then v1 … vn –2 vn vn-1(done) If {v1 , v2 , …, vn –1} → vn then v1 … vn –1 vn (done)
26
vn v1
v3
v4 vk –1 vk vn –1
… …
Trees
An undirected graph G = (V, E) is a tree if it is connected; and it does not have any cycle. Examples:
Not a tree; it has cycle
Not a tree; it is not connected
A tree
27
Trees
Examples:
v (no. of vertices) = 5 e (no. of edges) = 4 v = e+ 1
v=7 e=6 v=e+1
v=3 e=2 v = e +1
28
Trees
Theorem: For any tree G = (V, E), we have |V| = |E| + 1. Proof. By induction. The equality holds trivially when the tree has only one vertex. Suppose it is true for any tree with less than k vertices, and we consider any tree with k vertices. We explore the tree by moving forward as follows: Pick any vertex u. Since the graph is connected, it has an "outgoing" edge (u,v). Move forward to v. If v has "outgoing" edge (v, w), Move forward to w. Repeatedly moving forward. Since there are only |V| vertices, and there is no cycle, we will stuck at some point.
29
Trees
Theorem: For any tree G = (V, E), we have |V| = |E| + 1. Proof. By induction. … Repeatedly moving forward. Since there are only |V| vertices, and there is no cycle, we will stuck at some point.
After deletion, the new tree is still a tree (i) still connect; (ii) no cycle. By induction: |V'| = |E'| + 1. Since |V| = |V'| + 1, |E| = |E'| + 1, we have |V| = |E| + 1. delete this vertex, and this edge. 30
Planar graph
An (undirected, connected) graph is planar if we can draw the graph on the plane such that there are no crossing edges. Example.
Planar
Non-planar: No matter how hard we try, we cannot draw the graph with no crossing edges.
31
Planar graph
A planar graph divides the plane into certain parts, called faces.
(ii) (i) (i)
(ii) (iii)
(iv)
Planar Two faces. Four faces.
32
Planar graph
A planar graph divides the plane into certain parts, called faces.
(ii) (i) (i)
(ii) (iii)
(iv)
Planar f (no. of faces) =2 v (no. of vertices) = 4 e (no. of edges) = 4 f+v=e+2 f=4 v=5 e=7 f+v=e+2
33
Planar graph
Theorem (Euler). For any (connected) planar G = (V, E) with f faces, we have f + |V| = |E| + 2. Proof.
dams f = no. of basins + 1 (for sea) v = no. of towers e = no. of dams
watchtowers
Sea
basins
Imagine we blow-up the dams one by one to flood all the basins. We only blow up a dam only if one side of the dam is flood, and the other side is dry. 34
Planar graph
Theorem (Euler). For any (connected) planar G = (V, E) with f faces, we have f + |V| = |E| + 2. Proof.
1
dams f = no. of basins + 1 (for sea) v = no. of towers e = no. of dams
6 5
watchtowers
3
2
4
Sea
basins
blow one dam flood one basin Since there are f-1 basins, we have blown f-1 dams.
35
Planar graph
Theorem (Euler). For any (connected) planar G = (V, E) with f faces, we have f + |V| = |E| + 2. Proof.
dams f = no. of basins + 1 (for sea) v = no. of towers e = no. of dams
watchtowers
Sea
basins
blow one dam flood one basin Since there are f-1 basins, we have blown f-1 dams.
Note that the remaining dams, together with the watchtowers, form a tree. We have v = (e – (f-1)) + 1 f + v = e + 2. 36
Planar graph
Theorem: K5 is not planar. Proof. Suppose K5 is planar. v=5 e = 10 Then, by the Euler theorem, f = e – v + 2 = 7. On the other hand, since every face has at least 3 edges, and each edge is shared by two faces, we have 2e≥3f e ≥ 10.5, contradiction.
37
Planar graph
Theorem: A planar of v nodes has at most 3v – 6 edges. Proof. Since planar, we have v + f = e + 2. Since every face has at least 3 edges, and every edge is shared by two face, we have 2e ≥ 3f, or equivalently, f ≤ 2e/3. Combining the two inequalities, we have e – v + 2 ≤ 2e/3, or equivalently, e ≤ 3v – 6.
38