Mathematics for Computer Science - PowerPoint PPT Presentation

1 / 80
About This Presentation
Title:

Mathematics for Computer Science

Description:

Graphs G1 and G2 are isomorphic: there is an exact correspondence ... Self-test: show every 5-vertex tree isomorphic to one of these. Solution to Self-test ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 81
Provided by: leonvand
Category:

less

Transcript and Presenter's Notes

Title: Mathematics for Computer Science


1
Mathematics for Computer Science
  • Lecture 10 Graphs (3)
  • Leon van der Torre

2
Slides
  • 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
3
Connections, not Layout
Same graph, different layouts
4
Isomorphic Graphs
Same graph, different labels
5
Graph 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

6
Are these Isomorphic?
7
Show a Bijection
bijection f(Dog) beef f(Cat) tuna f(Cow)
hay f(Pig) corn
Check edge preservation
8
Finding the Mapping
  • Not easy --many possible mappings
  • Can test for properties
  • preserved under isomorphism
  • of nodes, edges
  • degree distributions
  • length of paths cycles

9
Non-isomorphism
degree 2
all degree 3
10
Exercise
  • 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

11
Possible Graph?
Is there a graph with vertex degrees 2,2,1?
NO!
12
An Impossible Graph
221 odd
  • The Handshaking Lemma
  • sum of degrees is even.

13
The Handshaking Lemma
Proof Each edge contributes 2 to the sum on the
right
14
Exercise
  • 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.

15
Paths Simple Paths
  • Path sequence of vertices

Simple path all different
16
Connectedness
  • 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

17
Paths Simple Paths
  • Lemma
  • The shortest path connecting
  • two vertices is simple!

18
Connected Components
  • The more connected components,
  • the more broken up" the graph is.

3 connected components
19
Connected Components
  • The connected component
  • of vertex v

20
Connected Components
  • A graph is connected
  • iff it has only
  • 1 connected component

21
Cycles
  • Cycle path from v0 to v0

22
Trees
  • A tree is a connected graph
  • with no simple cycles.

23
some 5-vertex trees
24
Applications of Trees
  • Data structures for sorting, searching
  • Spanning Trees
  • Game Trees (alpha-beta trees)
  • Pre?x codes (Huffman encoding)
  • Many algorithms based on trees

25
Tree Isomorphisms
same
26
Equivalent 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.

27
Be careful
  • ?A tree is a graph with 1 more vertex than edges?
  • NO

28
the only 5-vertex Trees
Self-test show every 5-vertex tree isomorphic to
one of these
29
Solution 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

30
Spanning Trees
  • a spanning tree of a connected graph is a tree
  • obtained by deleting edges
  • Always exists
  • subgraph with minimum edges
  • connecting all vertices

31
Spanning tree example
graph courtesy of Steven Rudich, CMU
32
Flight Gates
  • flights need gates, but times overlap.
  • how many gates needed?

33
Airline Schedule
122 145 67 257 306 99
Flights
34
Model as a Graph
145
306
99
35
Model as a Graph
36
Color vertices
  • so adjacent vertices have
  • different colors.
  • colors gates needed

37
Coloring the Vertices
assign gates
4 colors 4 gates
38
Better coloring
3 colors 3 gates
39
Final Exams
  • subjects conflict if student
  • takes both, so
  • need different time slots.
  • how short an exam period?

40
Model as a Graph
8.02
6.042
18.02
assign times
3.091
4 time slots (best possible)
6.001
41
Map Coloring
42
Four 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
43
Chromatic Number
  • min colors for G is
  • chromatic number, ?(G)
  • lemma
  • ?(tree) 2

44
Trees are 2-colorable
  • Pick any vertex as root.
  • if (unique) path from root is
  • even length
  • odd length

45
Simple Cycles
46
Complete Graph K5
47
Bounded 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
49
Exercise
  • 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?
50
Compatible Boys Girls
51
Compatible Boys Girls
match each girl to a unique compatible boy
52
Compatible Boys Girls
53
Compatible Boys Girls
B
G
suppose this edge was missing
54
Compatible Boys Girls
no match possible
55
No match possible
because of bottleneck
56
Bottleneck condition
B
G
N(S)2
S3
57
Bottleneck Lemma
bottleneck not enough boys for some set of girls.
  • If there is a bottleneck, then no match is
    possible.

58
Halls 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)

59
Halls Theorem
  • There is a perfect match iff there are no
    bottlenecks.
  • Lots of elegant uses in applications proofs

60
Planar Graphs
61
Planar Graphs
A graph is planar if there is a way to draw it in
the plane without edges crossing.
62
Planar Graphs
Maps are 2-connected planar graphs
  • General connected planar graphs may have
  • dongles

cross bars
63
A Planar Graph
(wait! also the outer face)
with 3 faces
4
4
64
Planar Graphs
draw it edge by edge
65
Planar Graphs
and record faces while drawing
graph
faces
(the outer face)
66
Planar Graphs
and record faces while drawing
graph
faces
(the outer face)
67
Planar Graphs
and record faces while drawing
graph
faces
(the outer face)
68
If you like curves
  • With same faces, you can draw the graph in the
    plane big or small, curvy or straight

4
2
1
3
69
Planar Drawing Faces
  • A planar embedding is a graph and its faces.
  • The same planar graph may have different
    embeddings.

70
Recursive 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.

71
Adding 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
78
Euler's Formula
If a planar embedding has v vertices, e edges,
and f faces, then v e f 2
79
Euler's Formula
  • Proof by structural induction on embeddings
  • base case 1 vertex

v 1, f 1, e 0 1?0?1 2
80
Adding 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

81
Adding 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

82
Homework
  • Outils mathématiques pour l'informaticien,
  • Section 6.3
Write a Comment
User Comments (0)
About PowerShow.com