Graphs Eulerian and Hamiltonian Applications Graph Layout Software
Total Page:16
File Type:pdf, Size:1020Kb
Graphs Eulerian and Hamiltonian Applications Graph layout software Graphs SET07106 Mathematics for Software Engineering School of Computing Edinburgh Napier University Module 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 5 1 3 45 7 9 a e a 4 c 7 d d z 9 3 e c 1 z { (a,5), (e,5),(e,4),(z,7) } 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 Students Subjects Tim maths Mary biology John computing Sue Pete science John Tim biology Petecomputing maths Sue Mary science Copyright Edinburgh Napier University Graphs Slide 4/31 Graphs Eulerian and Hamiltonian Applications Graph layout software A graph consists of nodes (vertices) and edges John Tim biology Petecomputing maths Sue Mary science Copyright Edinburgh Napier University Graphs Slide 5/31 Graphs Eulerian and Hamiltonian Applications Graph layout software Undirected and directed graphs John Tim biology Petecomputing maths Sue Mary science John Tim biology Petecomputing maths Sue Mary science 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 John Tim biology Petecomputing maths Sue Mary science 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. Tim Pete computing maths Sue Mary science 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 K¨onigsberg (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 K¨onigsberg This is graph problem. Euler asserted that a graph has a Eulerian path if the graph is connected and has either no or two nodes with an odd number of edges. 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 of cities? A problem of I optimisation I planning A graph where the edges are labelled with the distances between the cities. Among all the Hamiltonian paths, find the one which minimises distances. Copyright Edinburgh Napier University Graphs Slide 17/31 Graphs Eulerian and Hamiltonian Applications Graph layout software Sudoku 1 2 2 1 A bipartite graph. Copyright Edinburgh Napier University Graphs Slide 18/31 Graphs Eulerian and Hamiltonian Applications Graph layout software Sudoku 1 2 3 2 3 1 3 1 2 1 2 3 4 5 6 7 8 9 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 6 degrees 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 clustering coefficient of a random graph with the same number of nodes and 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 From Wolfram MathWorld: “the only good null graph is a dead null graph” 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 point in it. 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 point in 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 Susan Robert Mary friend friend Robert knows knows friend knows Paul knows Paul knows knows John friend Mary Susan 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 -> node1 node0 -> node2 node2 -> node1 } John Paul Mary Copyright Edinburgh Napier University Graphs Slide 30/31 Graphs Eulerian and Hamiltonian Applications Graph layout software Hierarchical, radial, circular layouts: Rita Rita Sue Lisa Bart Lisa Mary Dora Jim Jim Bart Bob John Mary Paul Paul John John Sue Bob Dora Bart Paul Dora Lisa Bob Jim Mary Rita Sue Spring layouts: Bob Sue Bob Sue Rita Paul Mary Paul Mary Lisa John John Dora Bart Lisa Rita Dora Bart Jim Jim Copyright Edinburgh Napier University Graphs Slide 31/31.