Last%20time:%20terminology%20reminder%20w - PowerPoint PPT Presentation

About This Presentation
Title:

Last%20time:%20terminology%20reminder%20w

Description:

Register Allocation. Given a program, we want to execute it as quick as possible. ... Two variables have a conflict if they cannot be put into the same register. ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 34
Provided by: cse167
Category:

less

Transcript and Presenter's Notes

Title: Last%20time:%20terminology%20reminder%20w


1
Last time terminology reminder w
  • Simple graph
  • Vertex node
  • Edge
  • Degree
  • Weight
  • Neighbours
  • Complete
  • Dual
  • Bipartite
  • Planar
  • Cycle
  • Tree
  • Path
  • Circuit
  • Components
  • Spanning Tree

2
edge
vertex (node)
Vertex degree is 3
3
Spanning Trees
A spanning tree of a graph G is a tree that
touches every node of G and uses only edges from G
Every connected graph has a spanning tree
4
Dual Graph
Dual put a node in every face, and an edge
between every adjacent face
5
Graph Colouring
6
Graph Colouring
Graph Colouring Problem Given a graph, colour
all the vertices so that two adjacent vertices
get different colours.
Objective use minimum number of colours.
3-colourable
7
Optimal Colouring
Definition. min colors for G is chromatic
number, ?(G)
What graphs have chromatic number one?
when there are no edges
What graphs have chromatic number 2?
What graphs have chromatic number larger than 2?
A path? A cycle? A triangle?
8
Simple Cycles
9
Complete Graphs
10
Wheels
11
Trees
Pick any vertex as root. if (unique) path from
root is even length odd length
Can prove more formally using induction
(classwork).
12
Chromatic Number
How do we estimate the chromatic number of a
graph?
If there is a complete subgraph of size k, then
we need at least k colours?
YES
Is the converse true?
If a graph has no complete subgraph of size 4,
then we can colour it using 4 colours?
NO
What graphs are 3-colourable?
No one knows
13
Flight Gates
flights need gates, but times overlap. how many
gates needed?
122 145 67 257 306 99
Flights
14
Conflict Graph
145
  • Each vertex represents a flight
  • Each edge represents a conflict

306
99
15
Graph Colouring
257
122
145
67
306
9
There is a k-colouring in this graph iff the
flights can be scheduled using k gates.
gt If there is a schedule, the flights scheduled
at the same gate have no conflict, and so we can
colour the graph by using one colour for flights
in each gate. lt If there is a graph colouring,
then the vertices using each colour have no
conflict, and so we can schedule the flights
having the same colour in one gate.
16
Colouring the Vertices
assign gates
4 colors 4 gates
17
Better Colouring
3 colors 3 gates
18
Final Exams
subjects conflict if student takes both, so need
different time slots. how short an exam period?
This is a graph colouring problem.
Each vertex is a course, two courses have an edge
if there is a conflict.
The graph has a k-colouring if and only if the
exams can be scheduled in k days.
19
Frequency Assignment
Assign frequencies to radio stations to avoid
interference.
minimum number of
20
Register Allocation
  • Given a program, we want to execute it as quick
    as possible.
  • Calculations can be done most quickly if the
    values are stored in registers.
  • But registers are very expensive, and there are
    only a few in a computer.
  • Therefore we need to use the registers
    efficiently.

This is a graph colouring problem.
21
Register Allocation
  • Each node is a variable.
  • Two variables have a conflict if they cannot be
    put into the same register.

a and b cannot use the same register, because
they store different values. c and d cannot use
the same register otherwise the value of c is
overwritten.
Each colour corresponds to a register.
22
Good News
For some special graphs, we know exactly when
they are k-colourable.
Interval graphs (conflict graphs of intervals)
b
b
d
d
a
a
c
c
For interval graphs,
minimum number of colours need maximum size of
a complete subgraph
So the flight gate problem and the register
allocation can be solved.
23
Map Colouring
Colour the map using minimum number of colours so
that two countries sharing a border are assigned
different colours.
24
Map Colouring
NO
Can we draw a map which needs 5 colours?
NO
Conjecture (1852) Every map is 4-colourable.
Proof by Kempe 1879, an error is found 11 years
later.
(Kempe 1879) Every map is 5-colourable.
Theorem (Apple Haken 1977). Every map is
4-colourable.
The proof is computer assisted, some mathematics
are still not happy.
25
A graph is planar if it can be drawn in the plane
without crossing edges
26
Non-Planar Graphs
27
Eulers Formula
If a connected planar graph has v vertices, e
edges, and f faces, then v e f 2
v5, e5, f2
v6, e10, f6
v9, e8, f1
28
Let G be the dual graph of G
Let T be a spanning tree of G
Let T be the graph where there is an edge in the
dual graph for each edge in G T
Then T is a spanning tree for G (Justify!)
n eT 1
n f eT eT 2
e 2
f eT 1
29
Applications of Eulers Formula
(Last time)
Claim. Every simple planar graph has a vertex of
degree at most 5.
(Proof by contradiction)
30
Applications of Eulers Formula
Claim. If G is a simple planar graph with at
least 3 nodes, then G has a node of degree at
most 5
Claim. If G is a simple planar graph with at
least 3 vertices, then e lt 3v-6
Let be the face
lengths.
Note that
because each edge contributes 2 to the sum
Contributes one to two faces
Contributes two to one face
31
Application of Eulers Formula
Claim. If G is a simple planar graph with at
least 3 vertices, then e lt 3v-6
Let be the face
lengths.
Note that
Since the graph is simple, each face is of length
at least 3.
So
Since e vf-2, this implies
32
6-Colouring Planar Graphs
Claim. Every simple planar graph has a vertex of
degree at most 5.
Theorem. Every planar graph is 6-colourable.
v
  1. Proof by induction on the number of vertices.
  2. Let v be a vertex of degree at most 5.
  3. Remove v from the planar graph G.
  4. Note that G-v is still a planar graph.
  5. By induction, G-v is 6-colourable.
  6. Since v has at most 5 neighbours,
  7. v can always choose a colour (from the 6 colours).

G-v
33
To Remember
  • Graph coloring
  • Mapping real-world problems to graph colouring
  • Planar Graphs
  • Definition
  • Eulers Theorem
  • Coloring Planar Graphs
  • Proving techniques
  • Dual graph
Write a Comment
User Comments (0)
About PowerShow.com