LECTURE NOTES 1 - Introduction To Graphs To Post
LECTURE NOTES 1 - Introduction To Graphs To Post
Basic Concepts
DR Karanja
1
Graph Theory - History
Leonhard Euler's paper on
“Seven Bridges of
Königsberg” ,
published in 1736.
02/15/11 2
Bridges of Königsberg
02/15/11 3
Bridges of Königsberg
4
Bridges of Königsberg
5
Famous problems
“The traveling salesman problem”
A traveling salesman is to visit a number of cities; how
to plan the trip so every city is visited once and just
once and the whole trip is as short as possible ?
6
Famous problems
In 1852 Francis Guthrie posed the “four color
problem” which asks if it is possible to color,
using only four colors, any map of countries in
such a way as to prevent two bordering
countries from having the same color.
8
What is a graph?
That’s (almost) it
also directedness, parallel
edges, self-connection,
weighted edges, node values…
Graph
02/15/11 KARANJA EVANS 9
Why are graphs useful?
The structure of relationships between
system elements provides information about
system properties
Bridges of Königsberg – the graph structure
demonstrated the lack of the property in
question
Small world networks – the way in which the
desired property was obtained informed
understanding of the network structure
10
Structures and structural metrics
Graph structures are used to isolate
interesting or important sections of a graph
Structural metrics provide a measurement of
a structural property of a graph
Global metrics refer to a whole graph
Local metrics refer to a single node in a graph
11
Graph structures
Identify interesting sections of a graph
Interesting because they form a significant
domain-specific structure, or because they
significantly contribute to graph properties
A subset of the nodes and edges in a graph
that possess certain characteristics, or relate
to each other in particular ways
i.e., a subgraph
12
Some applications of Graph Theory
Models for communications and electrical
networks
Models for computer architectures
Network optimization models for operations
analysis, including scheduling and job
assignment
Analysis of Finite State Machines
Parsing and code optimization in compilers
13
Application Examples
Cost of wiring electronic components
Shortest route between two cities.
Shortest distance between all pairs of cities in
a road atlas.
Matching / Resource Allocation
Visibility / Coverage
14
more application Examples
Flow of material
liquid flowing through pipes
current through electrical networks
information through communication networks
parts through an assembly line
15
Task scheduling
KARANJA EVANS 16
Scheduling Example
17
Scheduling Example (cont.)
18
more examples: Friends of friends
Social experiments have demonstrated that
the world is a small place after all
There is a high probability of you having an
indirect connection, through a small number of
friends, to a total stranger
In fact, it is postulated that a connection can
be drawn between two random people in a
very small number (<6) of links
19
Friends of friends
In a social network, a
common default
assumption was that
connections were
localised
Distant nodes take many
links to reach
21
Communities
Vertices
Edges
26
What makes a problem graph-like?
There are two components to a graph
Nodes and edges
In graph-like problems, these components
have natural correspondences to problem
elements
Entities are nodes and interactions between
entities are edges
Most complex systems are graph-like
Transportation networks
Nodes are cities, transfer
points or depots, edges are
roads or transport routes
SEE THIS FOR DETAILED NAIROBI MAP
http://www.traveldodo.com/webmaster/ken
ya/nairobi/
OR GO TO
http://kijabe.org/nairobi/nbimap.gif
30
ROUTING IN NAIROBI
http://kijabe.org/nairobi/nbimap.gif
.
31
Basic Graph Definitions
A graph is a mathematical object that is used to
model different situations – objects and processes:
Linked list
Tree (partial instance of graph)
Flowchart of a program
City map
Electric circuits
Course curriculum 32
Vertices and Edges
2 2
3 3
1 1
4 4
Vertices: A,B,C,D
Edges: AB, AC, BC, CD
C
A B
A
B
C
D D
A B A B
C C
D D
These
02/15/11 are two different KARANJA
graphs EVANS 36
More definitions : Path
ABC A B
BACD
ABCABCABCD
BABAC C
D
37
More definitions :
Simple Path
No vertex is repeated.
ABCD
A B
D CA
DCB
AB
C
ABC D
02/15/11 KARANJA EVANS 38
More definitions : Cycle
A B
ABCA
BACB
CBAC
C
D
A graph without cycles is called acyclic graph. 39
More definitions : Loop
A B
C
D
40
Walks and Paths …in summary
V2 3
V3
1
2
V1 3
1
V6
4
4
V4 1 V5
A walk is an sequence of nodes (v1, v2,..., vL) such that
{(v1, v2), (v1, v2),..., (v1, v2)} E, e.g. (V2, V3,V6, V5,V3)
A cycle is an walk (v1, v2,..., vL) where v1=vL with no other nodes
repeated and L>3, e.g. (V1, V2,V5, V4,V1)
C
C D
D 42
Graphs and Trees
Source graph:
C D
E
43
Graphs and Trees
A
C
C
A
B
E
E B
D
Tree1: root A Tree2: root C
D
44
A spanning tree of an
undirected graph
A sub-graph that contains all the vertices, and no cycles.
A B A B
graph
spanning tree
C C
D D 45
Examples
A B A B
C D C D
A B
All spanning trees
of the graph on
the previous slide
C D
46
Complete graphs
Graphs with all edges present – each vertex is
connected to all other vertices
A B
Dense graphs:
relatively few of
the possible
edges are
C
D missing
Sparse graphs:
E relatively few of
the possible
edges are
A complete graph present 47
Weighted graphs and
Networks
Weighted graphs – weights are assigned to each
edge (e.g. road map)
Networks: directed weighted graphs (some theories
allow networks to be undirected)
B 2
1
C
A 2
4
3
D
48
Graph Representation
Adjacency matrix
Adjacency lists
49
Adjacency matrix – undirected
graphs
Vertices: A,B,C,D
Edges: AC, AB, AD, BD
The matrix is symmetrical
A B
A B C D
A 0 1 1 1
B 1 0 0 1
C
C 1 0 0 1
D 1 1 0 0 D
50
Adjacency matrix – directed
graphs
Vertices: A,B,C,D
Edges: AC, AB, BD, DA
A B C D A B
A 0 1 1 0
B 0 0 0 1
C 0 0 0 0 C
D 1 0 0 0 D
Heads lists A B
A BCD
B AD C
C A D
D AB 52
Adjacency lists – directed
graphs
Vertices: A,B,C,D
Edges: AC, AB, BD, DA
A B
Heads lists
A BC
B D C
C =
D
D A
53
SOLVING GRAPH PROBLEMS
54
…A Mystery in the Library
Clue #1:
Double arrows imply TRUTH
57
Solving the Mystery
Undirected Testimony Graph
cycle
Burt Desmond
Abe
59
Solving the Mystery
One Scholars from the chordless 4-cycle must be a liar.
Therefore:
62
62
2. Nine Dot Problem
Draw no more than 4 straight lines (without lifting the pencil from the paper)
that cross through all nine dots
• • •
• • •
• • •
63
6 Matches Problem
Can yo
u m
ake 4qu
eilat
eral
tria
ngle
s?
64
Duncker’s Candle Problem
Duncker (1945) gave participants a candle, a box of
thumbtacks, and a book of matches, and asked them to
attach the candle to the wall so that it did not drip onto the
table below
65
Duncker’s Candle Problem
Solution is here
66
67