discussion #30 1/23 discussion #30 graph definitions and applications
Post on 22-Dec-2015
218 views
TRANSCRIPT
Discussion #30 1/23
Discussion #30
Graph Definitions and Applications
Discussion #30 2/23
Topics
• Motivation — graph applications
• Basic definitions
Discussion #30 3/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 4/23
Graphs in Programming
• Testing: paths in programs:
• Call graphs in programs• Software products consist of modules that invoke
each other.• Deadlock in operating systems
…
T F T
FT
F
Sequence If-then-else While Repeat-until Case
Discussion #30 5/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 6/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 7/23
Graphs in Database Design• Database design
– hypergraphs– equivalence classes (of 1-1 relationships) plus functional relationships
yield a DB with no redundancy.
• Generated, redundancy free relations– snap(StudentID, Name, Address, Phone); csg(Course, StudentID, Grade)– cr(Course, Room); cdh(Course, Day, Hour); cp(Course, Prerequisite)
Prerequisite
Course
StudentID
Grade
Room
Phone
NameAddress
Day
Hour
Discussion #30 8/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 9/23
Interpreters at the Great World Conference
Swedish—(
Booth #1 Booth #2 Booth #3 Booth #4
)—Indonesian
(1)Portuguese
Indonesian
(2)Polish
English
German
(3)Italian
Norwegian
English
(4)Korean
Turkish
(5)English
Polish
(6)Swedish
Turkish
(7)Spanish
Chinese
Japanese
(8)French
Portuguese
(9)Dutch
German
(10)Swedish
Norwegian
(11)Japanese
Indonesian
Russian
(12)Dutch
French
Chinese
Russian
Portuguese
(13)Polish
Italian
Swedish
(14)German
Chinese
Korean
(15)Dutch
Spanish
Indonesian
(16)French
English
Discussion #30 10/23
A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 B
Chinese 1 1 1
Dutch 1 1 1 1
English 1 1 1 1
French 1 1 1
German 1 1 1
Indonesian 1 1 1 1
Italian 1 1
Japanese 1 1
Korean 1 1
Norwegian 1 1
Polish 1 1 1
Portuguese 1 1 1
Russian 1 1
Spanish 1 1
Swedish 1 1 1 1
Turkish 1 1
Table of Spoken Languages
Discussion #30 11/23
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
B 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0
“Can Speak to” Matrix
Discussion #30 12/23
Graph of “Can Speak to” Matrix
10 3Norwegian English
2
Eng
lish
English
13Polish
Swed
ish
6
Swedish
Sw
edis
h
5
Polish
Polis
h
English
Eng
lish
14
Ger
man
9German
Germ
an
4
Turkish
Korean
7
Dutch
Dutch
DutchChinese
French
Chinese Chinese
Span
ish
8
1
11
Port
ugue
se
Portuguese
Portuguese
French
Japa
nese
Indonesian
Indonesian
Rus
sian
Indo
nesi
an
Italian
Swedish
Indonesian15
12
A B
Indonesian
Indo
nesi
an
Swedish
Swedish
16
French
Discussion #30 13/23
Project 5: Graph-Based Optimizationh :- P1, P2,…h,…Pn
• Acyclic: partial ordering, single pass
• Cyclic: multiple passes, least fixed point
• In both cases, we can ignore all rules not in the graph
h
P1 P2 … Pnh1 :- …h2,…h2 :- …h3,…h3 :- …h1,…
h1
h2
h3
h :- P1, P2, …, Pn
P1 :- … h
P1 P2 … Pn
Discussion #30 14/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.
• ExampleV = {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}) }
1 2
3
e1
e2
e3
e4 e5
• Hypergraph: (e6,{1,2,3})
e6
Multiset: set with duplicates
Discussion #30 15/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 16/23
Simple Graph = Graph• Eliminate f• Make edges either all ordered or all unordered.
G = (V, E), whereV is a set of nodes, andE is a set of all ordered or all
unordered pairs over V.• Example
Directed Graph or Digraph
Unordered graph, with multiset (e.g. {2, 2}) if needed1
2 3
V = {1, 2, 3}
E = {(1, 2), (2, 3), (3, 3)}
Discussion #30 17/23
Vocabulary for Simple Graphs
– d,u incident edge: edge “touching” a node
– d initiating node,originating node,tail node,predecessor
– d terminating node,ending node,head node,successor
(“d” for directed and “u” for undirected)
Discussion #30 18/23
Vocabulary (continued…)
– d out degreen…
m …– d in degree
– d,u total degree = in + out degree = degree (Note: a node with only a loop has
degree 2.)– d,u subgraph: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 19/23
Vocabulary (continued…)– u adjacent nodes: if there is an edge connecting them– d adjacent nodes: node b is adjacent to node a if there
is a directed edge from a to b– u complete: every node adjacent to every other node
(or to every node)
K1 K3K2
– u bipartite:- Two groups of nodes (often
different kinds)- Edges only connect between
groups (the two kinds)
K1K2 K4
… …
Discussion #30 20/23
Vocabulary (continued…)– d,u planar: can be drawn with no crossing lines
A graph is planar if and only if it does not contain either K5 or B3 as a subgraph.
K5
B3
Discussion #30 21/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, 3, 2, 4> is a path1
2
4
3
5
<1, 3> is a path
<5, 4, 3, 2, 4, 3> is a path
– d length of path = number of edges = number of nodes 1. (<1> is a degenerate path of
length 0.)
– u path & length: same idea (except can go both ways)
Discussion #30 22/23
Vocabulary (continued…)– d,u simple path (elementary path): all nodes distinct– d cycle: path that starts and stops at the same node
e.g. <4, 3, 2, 4>, <2, 4, 3, 2, 4, 3, 2>– d 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– d elementary cycle: no node (except the first/last) appears
twicee.g. <1, 2, 4, 2, 3, 1> is simple but not elementary;
<1, 2, 3, 1> and <2, 4, 2> are both elementary– u cycle: path that starts and stops at the same node; no edge
traversed in both directions.– u simple cycle: path of length 3 where only the first and
last nodes are repeated.
not a simple cycle not a simple cycle simple cycle– d,u acyclic: no cycle in graph
Discussion #30 23/23
Vocabulary (continued…)– d path relation: {(x,y)| a path exists from x to
y}– d,u reachability of y from x: a path exists from x to y– d,u minimum path from x to y: a path of minimum
length from x to y– d,u distance from x to y: minimum path length– u connected: any two nodes reachable from
each other– d connected: ignore direction and use the
definition for undirected graphs
disconnected connected