Artificial Intelligence Graph theory G. Guérard Department of Nouvelles Energies Ecole Supérieur d Ingénieurs Léonard de Vinci Lecture 1 GG A.I. 1/37
Outline 1 Graph theory Undirected and directed graphs Degree 2 Basics properties Path and Cycles Specifications 3 Classic problems Eulerian circuit Hamiltonian circuit Spanning tree Graph Coloring GG A.I. 2/37
Introduction A graph is a mathematical object consisting of a set of: NODES - V EDGES - E GRAPH is denoted by G = (V, E ) n = V and m = E A graph captures pairwise relationship between objects. GG A.I. 3/37
Undirected graph Undirected graph An UNDIRECTED GRAPH is a pair: G = (V, E ) where V is a nonempty SET OF VERTICES and E = {(u, v) : u, v V } is a SET OF EDGES. Remark Let m = (p, q) E. This means that the edge m connects the vertex p and the vertex q. Moreover, in such a case p and q are called the ENDPOINTS of m and we say that p and q are incident with m, they are ADJACENT or neighbours of each other. GG A.I. 4/37
Example Undirected graph Consider the undirected graph G = (V, E ) where V = {a, b, c, d, e}, and E = {(a, b), (a, c), (a, e), (e, b), (d, b), (c, d), (d, e)}. Remark We usually use a graphical representation of the graph. The vertices are represented by points and the edges by lines connecting the points. GG A.I. 5/37
Example Bipartite Consider a set of discipline D = {A, B, C, D} and students S = {1, 2, 3, 4}. Every student is interested in some schools D i D. The situation can be easily modelled by the graph G = (D S, E ). GG A.I. 6/37
Special edges Multiedges MULTIEDGES are edges which connect the same pair of vertices and a LOOP connects the vertex with itself. A graph with multiedges and loops is called a MULTIGRAPH. GG A.I. 7/37
Special edges We can associated WEIGHTS to edges (see previous example). These weights can represent cast, profit, length, capacity, action, etc. of a given connection. Weight The weight is a mapping from the set of edges to a set of numbers or alphabet w : E R or Σ. The graph with weight function of numbers is called a NETWORK and denoted by G = (V, E, w). Alphabet or probability give two others types of graphs: automata and markov chain. GG A.I. 8/37
Example Weight Let us consider the graph G = (V, E, w) seen previously, and the weight function: e E (a, b) (a, c) (a, e) (d, b) (e, b) (d, e) (d, c) w(e) -9 3 6 0 12 8 0.7 GG A.I. 9/37
Directed graph Directed graph A DIRECTED GRAPH is a pair G = (V, E ) where V is a nonempty set of vertices and E = {(u, v) : u, v V } is a set of directed edges (or ARCS). If (p, q) E, p is the head of the arc and q is the tail of the arc. GG A.I. 10/37
Example Directed graph Consider the directed graph G = (V, E ) where V = {a, b, c, d, e}, and E = {(a, b), (a, c), (a, e), (e, b), (d, b), (c, d), (d, e)}. GG A.I. 11/37
Degree Undirected graph The DEGREE of the vertex v is the number of edges incident to the vertex, with loops counted twice. The degree of a vertex is denoted deg(v) or Γ(v). A vertex v with degree 0 is called an ISOLATED. A vertex with degree 1 is called an endvertex or a LEAF. The degree of the graph G, (G ) is the maximum degree of its vertices. (G ) = max Γ(V ). v V GG A.I. 12/37
Example Degree Consider the graph Isolated vertices are x 5 and x 7. Leaves are x 4 and x 6. (G ) = max v V Γ(V ) = deg(x 2) = 5. GG A.I. 13/37
Degree Directed graph The IN-DEGREE of a vertex v, Γ (v), is the number of head endpoints adjacent to v. The OUT-DEGREE of a vertex v, Γ + (v), is the number of head endpoints adjacent to v. The degree of a vertex is Γ(v) = Γ (v) + Γ + (v). A vertex s for which Γ (v) = 0 and Γ + (v) > 0 is called a SOURCE and a vertex t for which Γ (v) > 0 and Γ + (v) = 0 is called a SINK. GG A.I. 14/37
Example Degree Consider the directed graph Γ (x) = 3, Γ + (x) = 2; Γ (y) = 5, Γ + (y) = 1. (G ) = max Γ(V ) = deg(y) = 6. There is no source or sink v V (technically, y can be called a sink because we can t escape from y to another vertex). GG A.I. 15/37
Example Source and sink Consider the directed graph Sources are vertices a and c, sink is the vertex e. GG A.I. 16/37
Degree Theorem For any graph, we have v V deg(v) = 2 E. The demonstration is trivial, any edge connects two vertices. So an edge (directed or undirected) increase the total of degrees by two. Theorem The number of vertices of odd degree is even. The sum of all the degrees is equal to twice the number of edges. Since the sum of the degrees is even and the sum of the degrees of vertices with even degree is even, the sum of the degrees of vertices with odd degree must be even. If the sum of the degrees of vertices with odd degree is even, there must be an even number of those vertices. GG A.I. 17/37
Definition Path A PATH (or CHAIN in a directed graph) in a graph is a sequence of edges (or arcs) which connect a sequence of vertices. To be more specific, a sequence (e 1,..., e n ) is called a path of the LENGTH n if there are vertices v 0,..., v n such that e i = (v i 1, v i ), i = 1..n. The first vertex v 1 is called START vertex, and the last vertex v n is called END vertex. Both of them are called TERMINAL vertices of the path. If v 0 = v n then the sequence is called a closed path. A closed path which the edges and vertices are distinct (exept terminals) is called a CYCLE (or a CIRCUIT in directed graph). GG A.I. 18/37
Example Path Consider the graph (d, e, g, b, a) is a closed path. (d, g, b, a) is a cycle. GG A.I. 19/37
Definition Acyclic A graph without cycles is called ACYCLIC. Connected A graph is called CONNECTED if for any couple of vertices u and v there exists a path connecting u and v, i.e. with start vertex is u and end vertex is v. GG A.I. 20/37
Tree Tree A connected and acyclic graph is called a TREE. a, b, c, d are trees, e has a cycle. GG A.I. 21/37
Complete graph Complete graph A COMPLETE graph K n is the graph with n vertices and all the pairs of vertices are adjacent to each other. Theorem In any K n, deg(v) = n 1, v V. The number of edges is E = [ i= 1]n i = n(n 1) 2. GG A.I. 22/37
Subgraph Subgraph A graph H = (V H, E H ) is called a SUBGRAPH of G = (V, E ) when V H V and E H E. Consider graphs G 1 and G 2 are subgraphs of G. GG A.I. 23/37
Eulerian circuit Problem GIVEN THE GRAPH, IS IT POSSIBLE TO CONSTRUCT A PATH (OR A CYCLE) WHICH VISITS EACH EDGE EXACTLY ONCE? Eulerian circuit How can we recognize Eulerian graph? They have two characterizations: node degrees, existence of a special collection of cycles. Theorem For a connected graph G, the following statements are equivalent: G is Eulerian (1); Every vertex of G has even degree (2); The edges of G can be partitioned into edge-disjoint cycles (3). GG A.I. 24/37
Eulerian circuit Proof 1 > 2 Assume G is Eulerian there exists a circuit that includes every edge of G. Every time a circuit enters a node v on an edge, it leave on a different edge. Since the circuit never repeats an edge, the number of edges incident with v is even deg(v) is even. GG A.I. 25/37
Eulerian circuit Proof 2>3 Suppose every node of G has even degree. We use induction on the number of cycles in G. G is connected and without nodes of degree 1, so G is not a tree, Ghas at least one cycle C n1. Let G be the graph obtained by removing C n1 from G. All edges of G have even degree and we can proceed recursively to prove that G can be partitioned into cycles C n2... C nk. Then, C n1... C nk is a partition of G into edge-disjoint cycles. GG A.I. 26/37
Eulerian circuit Proof 3>1 Suppose that the edges of G can be partitioned into k edge-disjoint cycles C n1... C nk. Because G is connected, every such cycle is an Eulerian circuit which must share a node with another cycle these circuits can be patched until we obtain one Eulerian circuit which is the whole graph G. GG A.I. 27/37
Eulerian path Question How to recognize graph which contain an Eulerian path? Note that: If the graph is Eulerian, then it contains an Eulerian path because every Eulerian circuit is also a path. Corollary A connected graph G contains an Eulerian path iff there are at most two vertices of odd degree. GG A.I. 28/37
Hamiltonian circuit Problem GIVEN THE GRAPH, IS IT POSSIBLE TO CONSTRUCT A PATH (OR A CYCLE) WHICH VISITS EACH VERTEX EXACTLY ONCE? Hamiltonian circuit How can we recognize Eulerian graph? There is no simple characterisation for this problem. Hamiltonian graphs can have all even degrees, all odd degrees, or a mixture. GG A.I. 29/37
Hamiltonian circuit Dirac s Theorem Let G be a graph of order n 3. If deg(g ) n 2, then G is Hamiltonian. Dirac s Theorem 2 Let G be a graph of order n 3. If deg(x) + deg(y) n for all pairs of nonadjacent nodes x, y, then G is Hamiltonian. GG A.I. 30/37
Definition Spanning tree A SPANNING TREE T of an undirected graph G is a subgraph that is a tree which includes all of the vertices of G. A MINIMUM SPANNING TREE (MST) connects all the vertices together with the minimal total weighting for its edges (see KRUSKAL and PRIM). Applications In order to minimize the cost of power networks, wiring connections, piping, automatic speech recognition, etc., we use algorithms that gradually build a spanning tree (or many such trees) as intermediate steps in the process of finding the minimum spanning tree. The Internet and many other telecommunications networks have transmission links that connect nodes together in a mesh topology that includes some loops. In order to avoid bridge loops and routing loops, many routing protocols designed for such networks require each router to remember a spanning tree. GG A.I. 31/37
Kruskal s Algorithm KRUSKAL S ALGORITHM is a greedy algorithm for the MST problem. Initially, let T be the empty graph on V. Examine the edges in E in increasing order of weight: If an edge connects two unconnected components of T, then add the edge to T Else, discard the edge and continue. Terminate when there is only one connected component. GG A.I. 32/37
Prim s Algorithm PRIM S ALGORITHM is a greedy algorithm for the MST problem. Initialize a tree with a single vertex, chosen arbitrarily from the graph. Grow the tree by one edge: of the edges that connect the tree to vertices not yet in the tree, find the minimum-weight edge, and transfer it to the tree. Repeat step 2 (until all vertices are in the tree). GG A.I. 33/37
Definition Definition GRAPH COLORING is a special case of graph labeling; it is an assignment of labels traditionally called "colors" to elements of a graph subject to certain constraints. In its simplest form, it is a way of coloring the vertices of a graph such that no two adjacent vertices share the same color; this is called a VERTEX COLORING. Similarly, an EDGE COLORING assigns a color to each edge so that no two adjacent edges share the same color, and a face coloring of a planar graph assigns a color to each face or region so that no two faces that share a boundary have the same color. Without any qualification, a coloring is always a vertex coloring. GG A.I. 34/37
Definition Definition Given a graph G (V, E ) with vertex set V and edge set E, a k-colouring of G is a function C : V {1... k} that assigns distinct values to adjacent vertices. For each edge e = (u, v) E, we require C (u) = C (v). If G has a k-colouring then it is said to be k-colourable. In words, a graph is k-colourable if one can draw it in such a way that no two adjacent vertices have the same colour. The chromatic number χ(g ) is the smallest number k such that G is k-colourable. GG A.I. 35/37
Applications The problem of coloring a graph arises in many practical areas such as pattern matching, sports scheduling, designing seating plans, exam timetabling, the scheduling of taxis, and solving Sudoku puzzles. Example A given set of jobs need to be assigned to time slots, each job requires one such slot. Jobs can be scheduled in any order, but pairs of jobs may be in conflict in the sense that they may not be assigned to the same time slot, for example because they both rely on a shared resource. The corresponding graph contains a vertex for every job and an edge for every conflicting pair of jobs. The chromatic number of the graph is exactly the minimum makespan, the optimal time to finish all jobs without conflicts. GG A.I. 36/37
Fundamental knowledge YOU HAVE TO KNOW BEFORE THE TUTORIAL: 1 Caracteristics and differences between undirected and directed graphs; 2 Notion of degrees, how to calculate them; 3 Notion of path and cycles; 4 Hamiltonian and eulerian definitions (Problem block); 5 Kruskal and Prim s algorithms; 6 Graph coloration. GG A.I. 37/37