GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using adjacency matrices
Contents Introduction Paths and circuits Matrix representations of graphs
Introduction to Graphs DEF: A simple graph G = (V,E ) consists of a non-empty set V of vertices (or nodes) and a set E (possibly empty) of edges where each edge is associated with a set consisting of either one or two vertices called its endpoints. Q: For a set V with n elements, how many possible edges there?
Terminology Loop, parallel edges, isolated, adjacent Loop - an edge connects a vertex to itself Two edges connect the same pair of vertices are said to be parallel. Isolated vertex – unconnected vertex. Two vertices that are connected by an edge are called adjacent. An edge is said to be incident on each of its end points.
Example of a graph Vertex set = {u1, u2, u3} Edge set = {e1, e2, e3, e4} e1, e2, e3 are incident on u1 u2 and u3 are adjacent to u1 e4 is a loop e2 and e3 are parallel
Types of Graphs Directed – order counts when discussing edges Undirected (bidirectional) Weighted – each edge has a value associated with it Unweighted 21 April 2017 Graphs and Trees 6
Examples 21 April 2017 Graphs and Trees 7 http://richard.jones.name/google-hacks/google-cartography/google-cartography.html 21 April 2017 Graphs and Trees 7
Special Graphs Simple – does not have any loops or parallel edges Complete graphs – there is an edge “between” every possible tuple of vertices Bipartite graph – V can be partitioned into V1 and V2, such that: (x,y)E (xV1 yV2) (xV2 yV1) Sub graphs G1 is a subset of G2 iff Every vertex in G1 is in G2 Every edge in G1 is in G2 Connected graph – can get from any vertex to another via edges in the graph 21 April 2017 Graphs and Trees 8
Complete Graphs there is an edge “between” every possible tuple of vertices. |e| = C(n,2) = n. (n-1)/2
Bipartite graph A graph is bipartite if its vertices can be partitioned into two disjoint subsets U and V such that each edge connects a vertex from U to one from V.
Complete bipartite A bipartite graph is a complete bipartite graph if every vertex in U is connected to every vertex in V. If U has m elements and V has n, then we denote the resulting complete bipartite graph by Km,n. The illustration shows K3,2
Degree of Vertex Defined as the number of edges attached (incident) to the vertex. A loop is counted twice. 21 April 2017 Graphs and Trees 12
Handshake Theorem If G is any graph, then the sum of the degrees of all the vertices of G equals twice the number of edges of G. Specifically, if the vertices of G are v1, v2, …, vn, where n is a nonnegative integer, then: The total degree of G = d(v1)+d(v2)+…+d(vn) = 2 (the number of edges of G) 21 April 2017 Graphs and Trees 13
Total degree of a graph is even Prove that the total of the degrees of all vertices in a graph is even. Since the total degree equals 2 times of edges, which is an integer, the sum of all degree is even. 21 April 2017 Graphs and Trees 14
Whether certain graphs exist Draw a graph with the specified properties or show that no such graph exists. (a) A graph with four vertices of degrees 1,1,2, and 3 (b) A graph with four vertices of degrees 1,1,3 and 3 (c) A simple graph with four vertices of degrees 1,1,3 and 3
Even no. of vertices with odd degree In any graph, there are an even number of vertices with odd degree Is there a graph with ten vertices of degrees 1,1,2,2,2,3,4,4,4, and 6? 21 April 2017 Graphs and Trees 16
Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using adjacency matrices
Seven Bridges of Königsberg Is it possible for a person to take a walk around town, starting and ending at the same location and crossing each of the seven bridges exactly once? No 21 April 2017 Graphs and Trees 18
Definitions Terminology - Walk, path, simple path, circuit, simple circuit. Walk from two vertices is a finite alternating sequence of adjacent vertices and edges Trivial walk from v to v consists of single vertex v0e1v1e2…envn 21 April 2017 Graphs and Trees 19
Path Path – a walk that does not contain a repeated edge (may have a repeated vertex) v0e1v1e2…envn where all the ei are distinct Simple path – a path that does not contain a repeated vertex v0e1v1e2…envn where all the ei and vj are distinct
Circuit Closed walk – starts and ends at same vertex Circuit – a closed walk without repeated edge Simple circuit – a circuit with no repeated vertex except first and last
Connectedness Connectedness – if there is a walk from one to the other
Euler Circuits A circuit that contains every vertex and every edge of G. A sequence of adjacent vertices and edges that starts and ends at the same vertex, uses every vertex of G at least once, and uses every edge of G exactly once. 21 April 2017 Graphs and Trees 23
If a graph has an Euler circuit, every vertex has even degree. Contrapositive: if some vertex has odd degree, then the graph does not have an Euler circuit. 21 April 2017 Graphs and Trees 24
If every vertex of nonempty graph has even degree and if graph is connected, then the graph has an Euler circuit. 21 April 2017 Graphs and Trees 25
Euler Circuit A graph G has an Euler circuit if, and only if, G is connected and every vertex of G has even degree. 21 April 2017 Graphs and Trees 26
Hamiltonian Path A path in an undirected graph which visits each vertex exactly once. 21 April 2017 Graphs and Trees 27
Hamiltonian Circuit A simple circuit that includes every vertex of G. A sequence of adjacent vertices and distinct edges in which every vertex of G appears exactly once, except for the first and last, which are the same. 21 April 2017 Graphs and Trees 28
Hamiltonian Circuit Proved simple criterion for determining whether a graph has an Euler circuit No analogous criterion for determining whether a graph has a Hamiltonian circuit Nor is there an efficient algorithm for finding such an algorithm 21 April 2017 Graphs and Trees 29
Traveling Salesman Problem http://en.wikipedia.org/wiki/Traveling_Salesman_Problem 21 April 2017 Graphs and Trees 30
TSP One way to solve the general problem is to: Write down all Hamiltonian circuits Compute total distance for each Pick one for which total is minimal What if graph has 30 vertices: 29! =8.84 x 1030 different Hamiltonian circuits If each circuit could be found and total distance computed in a nanosecond, then would take: 2.8 x 1014 years!!! No known algorithm that is more efficient!!! Some that find “pretty good” solutions 21 April 2017 Graphs and Trees 31
Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using adjacency matrices
Matrix Representations of Graphs 21 April 2017 Graphs and Trees 33
Matrices and Connected Components 21 April 2017 Graphs and Trees 34
Counting Walks of Length n Matrix multiplication 21 April 2017 Graphs and Trees 35
How do these graphs relate? = 21 April 2017 Graphs and Trees 36
Summary