Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Graphs Eulerian and Hamiltonian Applications Graph layout software
Graphs
SET07106 Mathematics for Software Engineering
School of ComputingEdinburgh Napier UniversityModule Leader: Uta Priss
2010
Copyright Edinburgh Napier University Graphs Slide 1/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Outline
Graphs
Eulerian and Hamiltonian
Applications
Graph layout software
Copyright Edinburgh Napier University Graphs Slide 2/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Binary relations
7
(e,5), (e,4), (z,7) }{ (a,5),
a
d
c
e
z
5
47
91
3
acd
ze
1 3 4 95
Copyright Edinburgh Napier University Graphs Slide 3/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
A binary relation can be represented as a graph
biology
Students Subjects
computing
Tim
Sue
Pete maths
Maryscience
Tim
John
Pete
biologyMary
Suecomputing
science
maths
John
Copyright Edinburgh Napier University Graphs Slide 4/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
A graph consists of nodes (vertices) and edges
biology
computing
Tim
Sue
Pete maths
Maryscience
John
Copyright Edinburgh Napier University Graphs Slide 5/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Undirected and directed graphs
biology
computing
Tim
Sue
Pete maths
Maryscience
John
biology
computing
Tim
Sue
Pete maths
Maryscience
John
Copyright Edinburgh Napier University Graphs Slide 6/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
The complete graphs for n ≤ 6
Copyright Edinburgh Napier University Graphs Slide 7/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Exercises
I Draw the complete graph with 7 nodes.
I How many edges does every node have in a complete graph?
I How many edges does a complete graph have?
Copyright Edinburgh Napier University Graphs Slide 8/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
A graph can be connected or disconnected
biology
computing
Tim
Sue
Pete maths
Maryscience
John
Copyright Edinburgh Napier University Graphs Slide 9/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
A bipartite graph has two sets of nodes
Edges are from one set of nodes to the other.There are no edges within the same set of nodes.
science
mathscomputing
Tim
Sue
Pete
Mary
Copyright Edinburgh Napier University Graphs Slide 10/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Exercise
Are there any complete graphs which are bipartite?
Copyright Edinburgh Napier University Graphs Slide 11/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Can you draw this figure ...
in one go without starting and stopping in between?
Copyright Edinburgh Napier University Graphs Slide 12/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Eulerian path
Each edge is visited once.
����
����
����
����
����
Copyright Edinburgh Napier University Graphs Slide 13/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Seven bridges of Konigsberg (1735)
Walk through the city and cross each bridge exactly once.
Copyright Edinburgh Napier University Graphs Slide 14/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Seven bridges of Konigsberg
This is graph problem.
����
����
����������������������������������
�������������������������������
���
Euler asserted that a graph has a Eulerian path if the graph isconnected and has either no or two nodes with an odd number ofedges.
Copyright Edinburgh Napier University Graphs Slide 15/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Hamiltonian path
Each node is visited once.
����
����
����
����
����
����
����
����
����
����
����
����
����
����
����
����
Copyright Edinburgh Napier University Graphs Slide 16/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Travelling salesman problem
What is the shortest path for a salesman to visit a given set ofcities?A problem of
I optimisation
I planning
A graph where the edges are labelled with the distances betweenthe cities.Among all the Hamiltonian paths, find the one which minimisesdistances.
Copyright Edinburgh Napier University Graphs Slide 17/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Sudoku
2
����
����
12
1
A bipartite graph.
Copyright Edinburgh Napier University Graphs Slide 18/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Sudoku
7
1
1
1
2
2
2
3
3
3
1
6
8
2
4
9
3
5
A tripartite graph.
Copyright Edinburgh Napier University Graphs Slide 19/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
6 degrees of separation
Do you know the Prime Minister?Do you know someone who knows the Prime Minister?Do you know someone who knows someone who knows the PM?...
The claim: everybody is connected to everybody else by at most 6degrees of separation.=⇒ It is a small world.
Copyright Edinburgh Napier University Graphs Slide 20/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Small-world effect
Every node can be reached by every other node by a short path.
Examples:
I Social networks
I Internet
I Road maps
I Electric power grids
Copyright Edinburgh Napier University Graphs Slide 21/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Which of these have a small-world effect?
.
clique
hub resource
Copyright Edinburgh Napier University Graphs Slide 22/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Small-world networks
I Small world effect: small average node-to-node distance(shortest path length)
I Clustering coefficient that is larger than the clusteringcoefficient of a random graph with the same number of nodesand edges.
Having a large clustering coefficient means that“the people you know also know each other”.
Copyright Edinburgh Napier University Graphs Slide 23/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Other graph applications
I Links between webpages
I Sitemaps
I Flow charts, UML diagrams
I Database schemata, ER diagrams
I Class hierarchies
I Web site paths traversed by users
I XML tree structures and DTDs
Copyright Edinburgh Napier University Graphs Slide 24/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Picture of a Null Graph:
Copyright Edinburgh Napier University Graphs Slide 25/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Harary and Read (1973):Is the Null Graph a Pointless Concept?
“The graph with no points and no lines is discussed critically. ...No conclusion is reached.”
The question is not whether it exists, but whether there is a pointin it.
From Wolfram MathWorld:“the only good null graph is a dead null graph”
Copyright Edinburgh Napier University Graphs Slide 26/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Harary and Read (1973):Is the Null Graph a Pointless Concept?
“The graph with no points and no lines is discussed critically. ...No conclusion is reached.”
The question is not whether it exists, but whether there is a pointin it.
From Wolfram MathWorld:“the only good null graph is a dead null graph”
Copyright Edinburgh Napier University Graphs Slide 26/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Graphs are special kinds of vector graphics
I Moving or removing a node affects its edges.
I Graph editors provide graph layout algorithms.
John
Mary
knows Paul
knows
friend
Susan
knows
Robert
friend
John
Mary
knows Paul
knows
friend
Susan
knows
Robertfriend
Copyright Edinburgh Napier University Graphs Slide 27/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Graph layout software/editors
I TouchGraph, spring embedder algorithms
I Java toolkits: Prefuse, ...
I Graphviz: open source graph visualisation software
Copyright Edinburgh Napier University Graphs Slide 28/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Graphviz
I www.graphviz.org
I Directed and undirected graphs.
I Graph layouts: hierarchies, spring, radial, circular.
I Simple text-based format (called “dot format”).
I APIs for different programming languages exist.
I Many output formats: gif, jpg, svg, pdf, ...
Copyright Edinburgh Napier University Graphs Slide 29/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
The “dot format”
digraph names {node0 [label=’’John’’]node1 [label=’’Mary’’]node2 [label=’’Paul’’]node0 -> node1node0 -> node2node2 -> node1}
John
Mary
Paul
Copyright Edinburgh Napier University Graphs Slide 30/31
Graphs Eulerian and Hamiltonian Applications Graph layout software
Hierarchical, radial, circular layouts:
John
Mary
Paul
Sue Bob
Rita
Lisa
Jim
Dora
Bart John
Mary
Paul
Sue
Bob
Rita
Lisa
Jim
DoraBart
John
Mary
Paul
Sue
Bob
Rita
Lisa
Jim
Dora
Bart
Spring layouts:
John
MaryPaul
Sue
Bob
Rita
Lisa
Jim
Dora Bart
John
Mary Paul
Sue Bob
RitaLisa
Jim
Dora Bart
Copyright Edinburgh Napier University Graphs Slide 31/31