Download presentation
Presentation is loading. Please wait.
Published byAmberlynn Barber Modified over 9 years ago
1
1 CS104 : Discrete Structures Chapter V Graph Theory
2
2 A Graph, G = (V, E), is a data structure which consists of a nonempty set of vertices (or nodes), V, and a set of edges, E, that connect (some of) them. The set of vertices V of a graph G may be infinite. A graph with infinite vertex set is called infinite graph. A graph with finite vertex set is called finite graph. For example, V = {1, 2, 3, 4, 5} E = { (1,2), (1,3), (1,4), (2,3), (3,5), (4,5) } 1 2 3 4 5 Vertex (Node) Edge What is a Graph?
3
3 Computer Networks Electrical Circuits Road Map Computer Resistor/Inductor/… City Application of Graphs
4
4 An Undirected Graph is a graph where the edges have no directions. The edges in an undirected graph are called Undirected Edges For example, G = (V, E), where V = {1, 2, 3, 4, 5} and E = {(1,2), (1,3), (1,4), (2,3), (3,5), (4,5)} A Directed Graph or Digraph is a graph where each edge has a direction. The edges in a digraph are called Arcs or Directed Edges For example, G = (V, E), where V = {1, 2, 3, 4, 5, 6} and E = {(1,4), (2,1), (2,3), (3,2), (4,3), (4,5), (4,6), (5,3), (6,1), (6,5)} The edge (1, 4) = 1 → 4 where 1 is the tail and 4 is the head 1 2 3 4 5 Graph Categorization 1 4 3 6 5 2
5
5 1 2 3 4 5 40 70 60 20 50 10 A graph with both directed and undirected edges is called a mixed graph. Adjacent vertices: If (u, v) is an edge of the graph, then the nodes u and v are adjacent. An edge (u, v) is incident to vertices u and v. For example, Vertices 1 and 2 are adjacent, but vertices 2 and 5 are not adjacent A Weighted Graph is a graph where all the edges are assigned weights. If the same pair of vertices have more than one edges (multiple edges), that graph is called a Multigraph 1 2 3 Graph Categorization 1 2 3 4 5
6
6 Loop or self edges: An edge (u, u) is called a self edge or a loop. ( 1,1 ) and ( 4,4 ) are self edges Graphs that may include loops, and possibly multiple edges connecting same pair of nodes, are called pseudographs. In simple graphs (or graphs) loops and multiple edges are not permitted The complete graph on n vertices, K n, is the simple graph that contains exactly one edge between each pair of distinct nodes. 1 2 3 4 5 12 1 2 3 12 34 1 23 45 Graph Categorization
7
7 The cycle C n, n≥3, consists of n vertices v 1, v 2, ….., v n, and edges (v 1, v 2 ), (v 2, v 3 ), …, (v n-1, v n ), and (v n, v 1 ). That is, C n consists of n vertices and n edges. A simple graph G is called bipartite if its vertex set can be partitioned into two disjoint sets V 1 and V 2 such that every edge in the graph connects a vertex in V 1 and a vertex in V 2. When this condition holds, we call the pair (V 1, V 2 ) a bipartition of the vertex set V of G. 1 2 3 12 34 1 23 45 Graph Categorization
8
8 Example 1:- C 6 is bipartite, because its vertex set can be partitioned into two disjoint sets V 1 ={v 1,v 3,v 5 } and V 2 ={v 2,v 4,v 6 }, and every edge of C 6 connects a vertex in V 1 and a vertex in V 2. Example 2:- K 3 is not bipartite, because if we divide the vertex set into two disjoint sets, one set must contain two vertices. If the graph were bipartite, these two vertices could not be connected by an edge, but in K 3 each vertex is connected to every other vertex by an edge. Theorem:- A simple graph is bipartite if and only if it is possible to assigns one of two different colors to each vertex of the graph so that no two adjacent vertices are assigned the same color. Graph Categorization V 1 v 1. v 3. v 5. V 2. v 2. v 4. v 6
9
9 A Subgraph of graph G=(V,E) is a graph H=(U,F) such that U ⊆ V and F ⊆ E. A subgraph H is a proper subgraph of G if H≠G. The union of two simple graphs G 1 =(V 1, E 1 ) and G 2 =(V 2, E 2 ) is the simple graph with vertex set (V 1 υV 2 ) and edge set (E 1 υE 2 ). The union of G 1 and G 2 is denoted by G 1 υG 2. For example, 1 2 3 4 5 G=(V,E) 1 3 2 H=(U,F) Graph Categorization 1 2 3 4 G1G1 2 3 4 5 G2G2 1 2 3 4 5 G 1 U G 2
10
10 Degree of a Vertex : In an undirected graph, the no. of edges incident to the vertex. Degree of vertex v is denoted by deg(v). For example, deg(1)=3, deg(2)=2, deg(3)=2, deg(4)=1 and deg(5)=0. A vertex of degree zero is called isolated vertex. A vertex of degree one is called pendant vertex. For example, vertex 4 is pendant and vertex 5 is isolated. The Handshaking Theorem: - Let G=(V, E) be an undirected graph. Then 2|E| = ∑deg(v), ∀ v ∈ V Example 3:- How many edges are there in a graph with 10 vertices each of degree six? Solution:- Because the sum of the degrees of the vertices is 6x10=60, it follows that 2|E|=60. Therefore, |E|=30. Graph Terminology 1 2 3 4 5
11
11 In diagram, there are two types ofdegree of a vertex - in-degree and out-degree In-degree: In-degree of a vertex v, denoted by deg - (v), is the no. of edges entering the vertex in a digraph Out-Degree: Out-degree of a vertex v, denoted by deg + (v), is the no. of edges leaving the vertex For example, deg - (1)=3 and deg + (1)=1. deg - (2)=1 and deg + (2)=1. Theorem:- For a digraph G=(V, E), ∑deg - (v)+∑deg + (v)=|E|, ∀ v ∈ V 1 2 3 4 5 Graph Terminology
12
12 Adjacency Matrix:- The Adjacency Matrix A=(a i,j ) of a graph G=(V,E) with n nodes is an nXn zero-one matrix. Element of A can be defined as follows: a ij = 1, if (v i, v j ) Є E, = 0, otherwise Example 4: Find the adjacency matrices of the following graphs. 1 2 3 4 5 12345 101110 210100 311001 410001 500110 1 2 3 123 1010 2001 3110 Representation of Graphs
13
13 Adjacency Matrix of a Weighted Graph:- The weight of the edge can be shown in the matrix when the vertices are adjacent A nil value (0 or ∞) depending on the problem is used when they are not adjacent Example 5: Adjacency matrix to find the minimum distance between nodes Example 6: Draw graph with the adjacency matrix 123 1∞4∞ 2∞∞5 395∞ 1 2 3 9 4 5 Representation of Graphs 123 1∞19 21∞∞ 3∞8∞ 1 2 3 9 1 8
14
14 Adjacency List:- An Adjacency list is an array of lists, each list showing the vertices a given vertex is adjacent to…. Example 7: Find the adjacency list of the following graph. Adjacency List of a Weighted Graph:- The weight is included in the list Example 8: Find the adjacency list of the following graph. 1 2 3 4 5 1 2 3 4 5 2 13 15 15 1 2 3 9 4 5 1 2 3 2 4 3 5 1 9 2 5 Representation of Graphs
15
15 Incidence Matrix:- Let G=(V,E) be a graph with v 1, v 2, …, v n are vertices and e 1, e 2, …., v m are edges. Then the incidence matrix with respect to this ordering of V and E is the nxm matrix M=[m ij ], where m ij = 1, when edge e j is incidence on v i, = 0, otherwise Example 9: Find the incidence matrices of the following graphs. e1e1 e2e2 e3e3 e4e4 e5e5 e6e6 v1v1 111000 v2v2 100100 v3v3 010110 v4v4 001001 v5v5 000011 e1e1 e2e2 e3e3 v1v1 100 v2v2 011 v3v3 000 Representation of Graphs v1v1 v2v2 v3v3 v4v4 v5v5 e2e2 e5e5 e1e1 e4e4 e6e6 e3e3 v1v1 v2v2 v3v3 e1e1 e2e2 e3e3
16
16 Def:- The simple graphs G 1 =(V 1, E 1 ) and G 2 =(V 2, E 2 ) are isomorphic if there is one-to-one and onto function f from V 1 to V 2 with the property that a and b are adjacent in G 1 if and only if f(a) and f(b) are adjacent in G 2, for all a, b in V 1. Such a function f is called an isomorphism. Example 10: Show that the graphs G=(V, E) and H=(U, F) are isomorphic. Proof:- The function f with f(v 1 )=u 1, f(v 2 )=u 4, f(v 3 )=u 3, and f(v 4 )=u 2 is a one-to-one correspondence between V and U. Next, to verify that this function preserves adjacency also. Adjacency vertices in G are v 1 and v 2, v 1 and v 3, v 2 and v 4, and v 3 and v 4. Also, the pairs f(v 1 )=u 1 and f(v 2 )=u 4, f(v 1 )=u 1 and f(v 3 )=u 3, f(v 2 )=u 4 and f(v 4 )=u 2, f(v 3 )=u 3, and f(v 4 )=u 2 are adjacent in H. Isomorphism of Graphs v1v1 v2v2 v3v3 v4v4 u1u1 u2u2 u3u3 u4u4 G H
17
17 A a path a sequence of edges that begins at a vertex of a graph and travels from vertex to vertex along the edges of the graph. There can be more than one path between two vertices. Vertex u is reachable from v if there is a path from u to v. Paths from 5 to 1 are 5, 3, 1 and 5, 3, 2, 1 A Simple Path is a path, where all the vertices are distinct. For example, 1,4,5,3 is a simple path, but 1,4,5,4 is not Length of a path is the no. of edges considered in the path. Length of the path 1,4,5,3 is 3 A circuit is a path whose first and last vertices are the same. For example, the path 3,2,1,4,5,3 is a circuit 1 2 3 4 5 Connectivity
18
18 A Cycle is a circuit where all the vertices are distinct except for the first (and the last) vertex. For example, 1,4,5,3,1 is a cycle, but 1,4,5,4,1 is not a cycle. Hamiltonian Cycle: A Cycle that contains all the vertices of the graph. 1,4,5,3,2,1 is a Hamiltonian Cycle. A graph is said to be connected if there is at least one path from every vertex to every other vertex in the graph. An Euler circuit in a graph G is a simple circuit containing every edge of G. An Euler path in G is a simple path containing every edge of G. For example, G has an Euler circuit, but H does not have 1 2 3 4 5 Euler Paths 12 34 5 G 12 34 5 H
19
19 Tree: A connected undirected graph that contains no cycles Forest: A graph that does not contain a cycle The Spanning Tree of a Graph G is a subgraph of G that is a tree and contains all the vertices of G. 1 2 3 4 5 Tree 1 2 3 4 5 Forest Spanning Tree 1 2 3 4 5 Graph 1 2 3 4 5 Spanning Tree 1 3 4 5 Tree
20
20 End of Chapter V
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.