Discussion #30 Graph Definitions and Applications 1/23

advertisement
Discussion #30
Graph Definitions and Applications
Discussion #30
1/23
Topics
• Motivation — graph applications
• Basic definitions
Discussion #30
2/23
Graphs: Very Useful Abstractions
• Graphs apply to many diverse areas: social sciences,
linguistics, physical sciences, communication
engineering, and many more.
• Why? Because they are a useful abstraction.
– Abstractions capture the essence of a real-world problem.
– Abstractions discard irrelevant details and let us focus on
the essence of the problem to be solved.
– Abstractions lend themselves to precise (mathematical)
specification.
– Mathematically defined abstractions lead to correct
computer implementations.
Discussion #30
3/23
Graphs in Programming
• Testing: paths in programs:
T
T
F
F
F
…
T
Sequence
If-then-else
While
Repeat-until
Case
• Call graphs in programs
• Software products consist of modules that invoke
each other.
• Deadlock in operating systems
Discussion #30
4/23
Graphs in Transportation
& Product Delivery
• Airline connections: getting from here to
there
• Highways with mileage between cities
• Traveling salesman problem: visit all cities
with minimal distance
• Traffic networks studied by transportation
and city planners
• Pipelines for delivering water or gas
Discussion #30
5/23
Graphs in Networks
• Social networks
– Friend of a friend
– Co-collaborators
• Computer networks
– Connect all, minimal number of connections
– (Minimal) spanning trees, LANs, WANs
• Scheduling networks
– Workflow from source to sink
– Critical path, slack time
– Earliest starting time, latest completion time
Discussion #30
6/23
Graphs in Database Design
• Database design
– hypergraphs
–
• Generated, redundancy free relations
– snap(StudentID, Name, Address, Phone); csg(Course, StudentID, Grade)
– cr(Course, Room); cdh(Course, Day, Hour); cp(Course, Prerequisite)
Discussion #30
7/23
Problems that Don’t Initially Look Like
Graph Problems
Have you ever had to work your way through a maze of
interpreters at an international conference?
Swedish and Indonesian delegates wish to talk to each
other, but among the sixteen interpreters, not one
speaks both Swedish and Indonesian. A way to solve
this problem is to form a chain of interpreters.
There are, however, only four booths; interpreters must
be in booths, and each booth can contain only one
interpreter.
Problem: Does a solution exist? If so, which four
interpreters will you place in the booths?
Discussion #30
8/23
Interpreters at the Great World Conference
Swedish—(
)—Indonesian
Booth #1
Booth #2
Booth #3
Booth #4
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
Portuguese
Indonesian
Polish
English
German
Italian
Norwegian
English
Korean
Turkish
English
Polish
Swedish
Turkish
Spanish
Chinese
Japanese
French
Portuguese
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
Dutch
German
Swedish
Norwegian
Japanese
Indonesian
Russian
Dutch
French
Chinese
Russian
Portuguese
Polish
Italian
Swedish
German
Chinese
Korean
Dutch
Spanish
Indonesian
French
English
Discussion #30
9/23
Table of Spoken Languages
A
1
2
3
4
5
6
7
8
9
10
11
1
Chinese
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Portuguese
1
1
1
Russian
1
1
Spanish
1
Turkish
Discussion #30
1
1
Japanese
Swedish
1
1
1
Polish
1
1
1
B
1
1
Norwegian
1
1
1
Korean
16
1
1
Italian
15
1
1
1
Indonesian
14
1
French
German
13
1
Dutch
English
12
1
1
1
1
10/23
“Can Speak to” Matrix
A
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
B
A
0
0
0
0
0
0
1
0
0
0
1
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
1
1
0
0
1
0
1
2
0
0
0
0
0
1
0
0
0
1
0
0
0
1
1
0
0
0
3
0
0
0
0
0
1
0
0
0
0
1
0
0
1
0
0
1
0
4
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
5
0
0
1
1
0
0
0
0
0
0
0
0
0
1
0
0
1
0
6
1
0
0
0
1
0
0
0
0
0
1
0
0
1
0
0
0
0
7
0
0
0
0
0
0
0
0
0
0
0
1
1
0
1
1
0
0
8
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
9
0
0
1
0
0
0
0
0
0
0
0
0
1
0
1
1
0
0
10
1
0
0
1
0
0
1
0
0
0
0
0
0
0
0
0
0
0
11
0
1
0
0
0
0
0
1
0
0
0
0
1
0
0
1
0
1
12
0
1
0
0
0
0
0
1
1
1
0
1
0
0
1
1
1
0
13
1
0
1
1
0
1
1
0
0
0
0
0
0
0
0
0
0
0
14
0
0
1
0
1
0
0
1
0
1
0
0
1
0
0
0
0
0
15
0
1
0
0
0
0
0
1
0
1
0
1
1
0
0
0
0
1
16
0
0
0
1
0
1
0
0
1
0
0
0
1
0
0
0
0
0
0
1
Discussion #30
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
B
11/23
Graph of “Can Speak to” Matrix
5
Indonesian
esi
an
1
Por
tugu
ese
Fre
nch
ese
Por
tugu
ese
B
Ind
on
Japanese
sian
12
Chin
Eng
lish
Ch
ine
se
uese
Portug
Spa
nish
Korean
sh
rki
Tu
4
ese
Du
tch
tch
Du
ian
es
on
Chin
6
Rus
an
English
Germ
Swedish
Sw
edi
sh
Po
lis
Dutch
9
Indonesian
15
d
In
14
on
es
ian
ian
sh
Engli
s
one
Ind
16
3
German
h
French
h
10
sh
edi
Sw
Sw
ed
is
Norwegian
In
d
ch
en
Fr
Swedish
ian
Engl
is
man
A
Ita
l
ish
sh
2
Ger
i
ed
w
S
Polish
11
l
Eng
13
h
is h
Pol
8
7
Discussion #30
12/23
Project 5: Graph-Based Optimization
h :- P1, P2, …, Pn
P1 :- …
h
P1 P2
h :- P1, P2,…h,…Pn
h
… Pn
P1 P2
• Acyclic: partial ordering,
single pass
• Cyclic: multiple passes, least
fixed point
• In both cases, we can ignore
all rules not in the graph
Discussion #30
… Pn
h1 :- …h2,…
h2 :- …h3,…
h3 :- …h1,…
h1
h2
h3
13/23
Graph Definition
• A graph G = (V, E, f) is
– a set of vertices V (sometimes also called nodes)
– a set of edges E (sometimes also called arcs)
– a function f from the set of edges E to the set of ordered
and unordered pairs of elements of V.
• Example
Multiset: set
with duplicates
V = {1, 2, 3}, E = {e1, e2, e3, e4, e5},
f = { (e1,(1,2)), (e2,{1,2}), (e3,(1,2)), (e4,(1,1)),(e5,{2,2}) }
e3
e4
1
e2
2
e5
e1
e6
3
• Hypergraph: (e6,{1,2,3})
Discussion #30
14/23
“Weird” Variations of Graphs
• All kinds of “weird” variations and vocabulary:
– Hypergraph: has edges with more than 2 nodes
– Multigraph: has parallel edges
– Mixed graph: some nodes directed, some nodes
undirected
• We are not going to study “weird” graphs.
• How do we make graphs simple?
Discussion #30
15/23
Simple Graph = Graph
• Eliminate f
• Make edges either all ordered or all unordered.
G = (V, E), where
Directed Graph
or Digraph
V is a set of nodes, and
E is a set of all ordered or all
unordered pairs over V.
• Example
Unordered graph, with
multiset (e.g. {2, 2}) if
needed
1
V = {1, 2, 3}
2
Discussion #30
3
E = {(1, 2), (2, 3), (3, 3)}
16/23
Vocabulary for Simple Graphs
(“d” for directed and “u” for undirected)
– d,u
incident edge: edge “touching” a node
–d
initiating node,
originating node,
tail node,
predecessor
–d
terminating node,
ending node,
head node,
successor
Discussion #30
17/23
Vocabulary (continued…)
–d
out degree
–d
in degree
– d,u
total degree = in + out degree = degree
(Note: a node with only a loop has degree 2.)
subgraph:
– d,u
…
m
H is a subgraph of G, H  G,
if H is a graph and V(H)  V(G)
and E(H)  E(G).
Discussion #30
n
…

18/23
Vocabulary (continued…)
– u
– d
is
– u
adjacent nodes: if there is an edge connecting them
adjacent nodes: node b is adjacent to node a if there
a directed edge from a to b
complete: every node adjacent to every other node
(or to every node)
…
K2
K1
– u
K3
K4
…
K1
K2
bipartite:
- Two groups of nodes (often
different kinds)
- Edges only connect between
groups (the two kinds)
Discussion #30
19/23
Vocabulary (continued…)
– d,u
planar: can be drawn with no crossing lines


K5


B3
A graph is planar if and only if it does not contain either
K5 or B3 as a subgraph.
Discussion #30
20/23
Vocabulary (continued…)
– d
path:
– sequence of edges such that the head of the
previous is the tail of the next
– usually written as a sequence of nodes
1
4
5
<1, 3, 2, 4> is a path
<1, 3> is a path
2
– d
– u
Discussion #30
3
<5, 4, 3, 2, 4, 3> is a path
length of path = number of edges = number of
nodes  1. (<1> is a degenerate path of length 0.)
path & length: same idea (except can go both ways)
21/23
Vocabulary (continued…)
– d,u
– d
simple path (elementary path): all nodes distinct
cycle: path that starts and stops at the same node
e.g. <4, 3, 2, 4>, <2, 4, 3, 2, 4, 3, 2>
simple cycle: no edge appears more than once
e.g. <4, 3, 2, 4> is simple, <2, 4, 3, 2, 4, 3, 2> is not
elementary cycle: no node (except the first/last) appears twice
e.g. <1, 2, 4, 2, 3, 1> is simple but not elementary;
<1, 2, 3, 1> and <2, 4, 2> are both elementary
cycle: path that starts and stops at the same node; no edge
traversed in both directions.
simple cycle: path of length  3 where only the first and last
are repeated.
– d
– d
– u
– u
nodes
– d,u
not a simple cycle not a simple cycle
acyclic: no cycle in graph
Discussion #30
simple cycle
22/23
Vocabulary (continued…)
– d
– d,u
– d,u
– d,u
– u
– d
path relation: {(x,y)| a path exists from x to y}
reachability of y from x: a path exists from x to y
minimum path from x to y: a path of minimum
length from x to y
distance from x to y: minimum path length
connected: any two nodes reachable from each
other
connected: ignore direction and use the definition
for undirected graphs
disconnected
Discussion #30
connected
23/23
Download