Title: Mathematics for Computer Science
1Mathematics for Computer Science
- Lecture 10 Graphs (3)
- Leon van der Torre
2Slides
- Slides can be found on the internet
- These slides are based on MIT open courseware,
by A. Meyer
BECS - Bachelor of Engineering in Computer
Science
3Connections, not Layout
Same graph, different layouts
4Isomorphic Graphs
Same graph, different labels
5Graph Isomorphism
- Graphs G1 and G2 are isomorphic
- there is an exact correspondence
- between vertices of G1 and G2 that
- preserves edges.
- ? bijection f V1 ? V2
- uv is in E1 iff f(u)f(v) is in E2
6Are these Isomorphic?
7Show a Bijection
bijection f(Dog) beef f(Cat) tuna f(Cow)
hay f(Pig) corn
Check edge preservation
8Finding the Mapping
- Not easy --many possible mappings
- Can test for properties
- preserved under isomorphism
- of nodes, edges
- degree distributions
- length of paths cycles
9Non-isomorphism
degree 2
all degree 3
10Exercise
- Define an isomomorphism between the graphs, or
prove that there is none. - V1 1,2,3,4,5,6 , E1 12, 23, 34, 14, 15,
35, 45 - V2 1,2,3,4,5,6 , E2 12, 23, 34, 45, 51,
24, 25 - V1 1,2,3,4,5,6 , E1 12, 23, 34, 14, 45,
56, 26 - V2 a,b,c,d,e,f , E2 ab, bc, cd, de, ae,
ef, cf - V1 a,,h , E1 ab, bc, cd, ad, ef, fg, gh,
he, dh, bf - V2 s,, z , E2 st, tu, uv, sv,wx, xy,
yz,wz, sw, vz
11Possible Graph?
Is there a graph with vertex degrees 2,2,1?
NO!
12An Impossible Graph
221 odd
- The Handshaking Lemma
- sum of degrees is even.
13The Handshaking Lemma
Proof Each edge contributes 2 to the sum on the
right
14Exercise
- There is a party. Some people shake hands an even
number of times and some shake an odd number of
times. - Proposition an even number of people shake hands
an odd number of times. - Represent the party as a graph and the
proposition as graph theoretical property. - Prove the proposition.
15Paths Simple Paths
- Path sequence of vertices
Simple path all different
16Connectedness
- vertices v, w are connected iff
- there is a path starting at v and
- ending at w.
- A graph is connected iff every two of its
vertices are connected
17Paths Simple Paths
- Lemma
- The shortest path connecting
- two vertices is simple!
18Connected Components
- The more connected components,
- the more broken up" the graph is.
3 connected components
19Connected Components
- The connected component
- of vertex v
20Connected Components
- A graph is connected
- iff it has only
- 1 connected component
21Cycles
22Trees
- A tree is a connected graph
- with no simple cycles.
23some 5-vertex trees
24Applications of Trees
- Data structures for sorting, searching
- Spanning Trees
- Game Trees (alpha-beta trees)
- Pre?x codes (Huffman encoding)
- Many algorithms based on trees
25Tree Isomorphisms
same
26Equivalent Tree Definitions
- lemma A tree is a graph with a unique path
between any 2 vertices. - lemma A tree is a connected graph with
vertices 1 edges.
27Be careful
- ?A tree is a graph with 1 more vertex than edges?
- NO
28the only 5-vertex Trees
Self-test show every 5-vertex tree isomorphic to
one of these
29Solution to Self-test
- 5-vertex tree has 4 edges
- so sum of degrees is 8
- tree is connected
- so vertex degrees are gt 0
- leaves 3 degrees to distribute
- The only possibilities are
- 3 2 1 1 1
- 2 2 2 1 1
- 4 1 1 1 1
- these force unique connections
30Spanning Trees
- a spanning tree of a connected graph is a tree
- obtained by deleting edges
- Always exists
- subgraph with minimum edges
- connecting all vertices
31Spanning tree example
graph courtesy of Steven Rudich, CMU
32Flight Gates
- flights need gates, but times overlap.
- how many gates needed?
33Airline Schedule
122 145 67 257 306 99
Flights
34Model as a Graph
145
306
99
35Model as a Graph
36Color vertices
- so adjacent vertices have
- different colors.
- colors gates needed
37Coloring the Vertices
assign gates
4 colors 4 gates
38Better coloring
3 colors 3 gates
39Final Exams
- subjects conflict if student
- takes both, so
- need different time slots.
- how short an exam period?
40Model as a Graph
8.02
6.042
18.02
assign times
3.091
4 time slots (best possible)
6.001
41Map Coloring
42Four Color Theorem
any planar map is 4-colorable. 1850s false
proof published (was correct for 5
colors). 1970s prf with much computing 1990s
much improved
43Chromatic Number
- min colors for G is
- chromatic number, ?(G)
- lemma
- ?(tree) 2
44Trees are 2-colorable
- Pick any vertex as root.
- if (unique) path from root is
- even length
- odd length
45Simple Cycles
46Complete Graph K5
47Bounded Degree
- if all vertex degrees k, then
by simple recursive coloring procedure
48- Prove that it can be colored with 3 colors -
Prove that it can not be colored with 2 colors
49Exercise
- A portion of a computer program consists of a
sequence of calculations where the results are
stored in variables - Inputs a, b
- 1. c a b
- 2. d a c
- 3. e c 3
- 4. f c - e
- 5. g a f
- 6. h f 1
- Outputs d, g, h
(a) Recast the register allocation problem as a
question about graph coloring. What do the
vertices correspond to? Under what conditions
should there be an edge between two vertices?
Construct the graph corresponding to the
example. (b) Color your graph using as few colors
as you can. Call the computers registers R1, R2,
etc. Describe the assignment of variables to
registers implied by your coloring. How many
registers do you need?
50Compatible Boys Girls
51Compatible Boys Girls
match each girl to a unique compatible boy
52Compatible Boys Girls
53Compatible Boys Girls
B
G
suppose this edge was missing
54Compatible Boys Girls
no match possible
55No match possible
because of bottleneck
56Bottleneck condition
B
G
N(S)2
S3
57Bottleneck Lemma
bottleneck not enough boys for some set of girls.
- If there is a bottleneck, then no match is
possible.
58Halls Theorem
- There is a perfect match iff there are no
bottlenecks. - Proof clever strong induction on girls.
- (Better proof using duality principle
- goes beyond course)
59Halls Theorem
- There is a perfect match iff there are no
bottlenecks. - Lots of elegant uses in applications proofs
60Planar Graphs
61Planar Graphs
A graph is planar if there is a way to draw it in
the plane without edges crossing.
62Planar Graphs
Maps are 2-connected planar graphs
- General connected planar graphs may have
- dongles
cross bars
63A Planar Graph
(wait! also the outer face)
with 3 faces
4
4
64Planar Graphs
draw it edge by edge
65Planar Graphs
and record faces while drawing
graph
faces
(the outer face)
66Planar Graphs
and record faces while drawing
graph
faces
(the outer face)
67Planar Graphs
and record faces while drawing
graph
faces
(the outer face)
68If you like curves
- With same faces, you can draw the graph in the
plane big or small, curvy or straight
4
2
1
3
69Planar Drawing Faces
- A planar embedding is a graph and its faces.
- The same planar graph may have different
embeddings.
70Recursive Def Planar Embeddings
- Base a graph consisting of a single vertex, v,
and no edges, along with a single face consisting
of the length 0 path from v to v, - is a PE.
71Adding an edge to an embedding
- Two constructor cases
- Attach edge from vertex on a face to a new
vertex. - Attach edge between vertices on a face.
72 Face Creation Rules
1) choose face
add edge to new vertex b
73 Face Creation Rules
1) choose face
new face
add edge to new vertex b
74 Face Creation Rules
1) choose face
nothing else changes
new face
75 Face Creation Rules
2) choose face
add edge across it
76 Face Creation Rules
2) choose face
splits into 2 faces
77 Face Creation Rules
2) choose face
b
b
a
a
splits into 2 faces
78Euler's Formula
If a planar embedding has v vertices, e edges,
and f faces, then v e f 2
79Euler's Formula
- Proof by structural induction on embeddings
- base case 1 vertex
v 1, f 1, e 0 1?0?1 2
80Adding an edge to a drawing
- Inductive step
- Case 1 edge to new vertex
- v increases by 1
- e increases by 1
- f stays the same
- so v e f stays the same
81Adding an edge to a drawing
- Inductive step
- Case 2 edge across face
- v stays the same
- e increases by 1
- f increases by 1
- so v e f stays the same
- Inductive steps
82Homework
- Outils mathématiques pour l'informaticien,
- Section 6.3