Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS100: Discrete structures

Similar presentations


Presentation on theme: "CS100: Discrete structures"— Presentation transcript:

1 CS100: Discrete structures
Computer Science Department Lecture 7: Graphs

2 Lecture Contents Types of Graphs Graph Terminology
Special Types of Graphs 7-Dec-18 Computer Science Department

3 Simple Directed Graphs
Types of Graphs Types of Graphs undirected Graphs Simple Graphs Multigraphs Pseudographs directed Graphs Simple Directed Graphs Directed Multigraphs 7-Dec-18 Computer Science Department

4 Undirected Graph A graph G = ( V , E ) consists of
V, a nonempty set of vertices (nodes) E, a set of edges (unordered pairs of distinct elements of V) 7-Dec-18 Computer Science Department

5 Types of undirected Graphs
Simple Graphs Each edge connects two different vertices No two edges connect the same pair of vertices Multigraphs Graphs that may have multiple edges connecting the same vertices Pseudographs Graphs that may include loops Possibly multiple edges connecting the same pair of vertices 7-Dec-18 Computer Science Department

6 Simple Graph Example San Francisco Denver Los Angeles New York Chicago Washington Detroit This simple graph represents a network that contains computers and telephone links between computers 7-Dec-18 Computer Science Department

7 Multigraph Example There can be multiple telephone lines between two computers in the network. Detroit New York San Francisco Chicago Denver Washington Los Angeles 7-Dec-18 Computer Science Department

8 Pseudograph Example Detroit Chicago New York San Francisco Denver Washington Los Angeles There can be telephone lines in the network from a computer to itself. 7-Dec-18 Computer Science Department

9 Directed Graph A directed graph (digraph) ( V , E ) consists of
V, a nonempty set of vertices E, a set of directed edges (arcs) Each directed edge is associated with an ordered pair of vertices. The directed edge associated with the ordered pair (u,v) is said to start at u and end at v. 7-Dec-18 Computer Science Department

10 Types of directed Graphs
Simple Directed Graph No loops No multiple directed edges Directed Multigraph Directed graphs that may have multiple directed edges from a vertex to a second (possibly the same) 7-Dec-18 Computer Science Department

11 Simple Directed Graph Example
The edges are ordered pairs of (not necessarily distinct) vertices. Detroit Chicago San Francisco New York Denver Washington Los Angeles Some telephone lines in the network may operate in only one direction. Those that operate in two directions are represented by pairs of edges in opposite directions. 7-Dec-18 Computer Science Department

12 Directed Multigraph Example
Detroit New York Chicago San Francisco Denver Washington Los Angeles There may be several one-way lines in the same direction from one computer to another in the network. 7-Dec-18 Computer Science Department

13 Graph Model Structure Three key questions can help us understand the structure of a graph: Are the edges of the graph undirected or directed (or both)? If the graph is undirected, are the multiple edges present that connect the same pair of vertices? If the graph is directed, are multiple directed edges present? Are the loops present? 7-Dec-18 Computer Science Department

14 Exercise Determine whether the graphs shown below have
directed or undirected edges, multiple edges, one or more loops A B 7-Dec-18 Computer Science Department

15 directed or undirected
Solution Graph directed or undirected multiple edges Loops Type A undirected multi-graph no loops Multigraph B directed directed multi-graph two loops Directed Multigraph 7-Dec-18 Computer Science Department

16 Summary Type Edges Loops Multiple Edges Simple Graph Undirected NO
Multigraph YES Pseudograph Simple Directed Graph Directed Directed Multigraph 7-Dec-18 Computer Science Department

17 Precedence Graphs In concurrent processing, some statements must be executed before other statements. A precedence graph represents these relationships. 7-Dec-18 Computer Science Department

18 Graph Terminology 7-Dec-18 Computer Science Department

19 Adjacent Vertices in Undirected Graphs
Two vertices, u and v in an undirected graph G are called adjacent (or neighbors) in G, if {u,v} is an edge of G. An edge e connecting u and v is called incident with vertices u and v, or is said to connect u and v. The vertices u and v are called endpoints of edge {u,v}. 7-Dec-18 Computer Science Department

20 Degree of a Vertex The degree of a vertex in an undirected graph is the number of edges incident with it, except that a loop at a vertex contributes twice to the degree of that vertex The degree of a vertex v is denoted by deg(v) 7-Dec-18 Computer Science Department

21 Example Find the degrees of all the vertices. Solution:
b g e c d f Find the degrees of all the vertices. Solution: deg(a)= , deg(b)= , deg(c)= , deg(d)= , deg(e)= , deg(f)= , deg(g)= . 7-Dec-18 Computer Science Department

22 Adjacent Vertices in Directed Graphs
When (u,v) is an edge of a directed graph G, u is said to be adjacent to (Neighbor) v . v is said to be adjacent from u . initial vertex terminal vertex (u ,v) 7-Dec-18 Computer Science Department

23 Degree of a Vertex In-degree of a vertex v Out-degree of a vertex v
The number of vertices adjacent to v (the number of edges with v as their terminal vertex) Denoted by deg(v) Out-degree of a vertex v The number of vertices adjacent from v (the number of edges with v as their initial vertex) Denoted by deg+(v) A loop at a vertex contributes 1 to both the in- degree and out-degree. 7-Dec-18 Computer Science Department

24 Degree of a Vertex : Example
Find the in-degrees and out-degrees of this digraph. 7-Dec-18 Computer Science Department

25 Degree of a Vertex : Example
In-degrees: deg-(a) = 2, deg-(b) = 2, deg-(c) = 3, deg-(d) = 2, deg-(e) = 3, deg-(f) = 0 Out-degrees: deg+(a) = 4, deg+(b) = 1, deg+(c) = 2, deg+(d) = 2, deg+(e) = 3, deg+(f) = 0 7-Dec-18 Computer Science Department

26 Theorem Let G = (V, E) be a graph with directed edges. Then:
The sum of the in-degrees of all vertices in a digraph = the sum of the out-degrees = the number of edges. (an edge is in for a vertex and out for the other) 7-Dec-18 Computer Science Department

27 Exercise For following graph, determine:
The number of vertices and edges. The in-degree and out-degree of each vertex for the given directed multi-graph. The sum of the in-degrees of the vertices and the sum of the out- degrees of the vertices directly. Show that they are both equal to the number of edges in the graph. 7-Dec-18 Computer Science Department

28 Solution |V|= 4, |E|= 8. The degrees are : deg−(a) =2, deg+(a) = 2, deg−(b) = 3, deg+(b) = 4, deg−(c) = 2, deg+(c) = 1, deg−(d) = 1,and deg+(d) = 1. The sum of the in-degrees of the vertices =8, The sum of the out-degrees of the vertices =8, |E|= The sum of the in/out-degrees of the vertices = 8 7-Dec-18 Computer Science Department

29 Complete graph The complete graph on n vertices (Kn) is the simple graph that contains exactly one edge between each pair of distinct vertices. The figures above represent the complete graphs, Kn , for n = 1, 2, 3, 4, 5, and 6. 7-Dec-18 Computer Science Department

30 cycle The cycle Cn (n  3), consists of n vertices v1, v2, …, vn and edges {v1,v2}, {v2,v3}, …, {vn-1,vn}, and {vn,v1}. C5 C6 C3 C4 Cycles: 7-Dec-18 Computer Science Department

31 WHEEL When a new vertex is added to a cycle Cn and this new vertex is connected to each of the n vertices in Cn, we obtain a wheel Wn. W5 W6 W3 W4 Wheels: 7-Dec-18 Computer Science Department

32 Bipartite Graph A simple graph is called bipartite if its vertex set V can be partitioned into two disjoint nonempty sets V1 and V2 such that every edge in the graph connects a vertex in V1 and a vertex in V2 (so that no edge in G connects either two vertices in V1 or two vertices in V2). b c a d e a b c d e 7-Dec-18 Computer Science Department

33 Bipartite Graph : Example 1
1 2 5 4 Is C6 Bipartite? Yes. Why? Because: its vertex set can be partitioned into the two sets V1 = {v1, v3, v5} and V2 = {v2, v4, v6} every edge of C6 connects a vertex in V1 with a vertex in V2 7-Dec-18 Computer Science Department

34 Bipartite Graph : Example 2
1 Is K3 Bipartite? No. Why not? Because: Each vertex in K3 is connected to every other vertex by an edge If we divide the vertex set of K3 into two disjoint sets, one set must contain two vertices These two vertices are connected by an edge But this can’t be the case if the graph is bipartite 7-Dec-18 Computer Science Department

35 Exercise Determine whether the graphs shown below are bipartite. Justify your answer. B A 7-Dec-18 Computer Science Department

36 Solution The graph is bipartite, its vertex set can be partitioned into two sets V1= { a, c } and V2 = { b, d, e }. The graph is bipartite, its vertex set can be partitioned into two sets V1= { c, f } and V2 = { a, b, d, e }. 7-Dec-18 Computer Science Department

37 Subgraph A subgraph of a graph G = (V,E) is a graph H = (W,F) where W  V and F  E. C5 K5 Is C5 a subgraph of K5? …... 7-Dec-18 Computer Science Department

38 Union The union of 2 simple graphs G1 = (V1, E1) and G2 = (V2, E2) is the simple graph with vertex set V = V1V2 and edge set E = E1E2. The union is denoted by G1G2. S5 a b c e d f C5 b a c e d W5 b d a c e f S5  C5 = W5 7-Dec-18 Computer Science Department

39 Representing Graphs 7-Dec-18 Computer Science Department

40 Adjacency Matrix A simple graph G = (V , E ) with n vertices can be represented by its adjacency matrix A, where the entry aij in row i and column j is: 7-Dec-18 Computer Science Department

41 Adjacency Matrix Example
W5 d b a c e f a b c d e f a b c d e f From To {v1,v2} row column 7-Dec-18 Computer Science Department

42 Incidence Matrix Let G = (V,E) be an undirected graph. Suppose v1,v2,v3,…,vn are the vertices and e1,e2,e3,…,em are the edges of G. The incidence matrix with respect to this ordering of V and E is the nm matrix M = [mij], where 7-Dec-18 Computer Science Department

43 Incidence Matrix Example
Represent the graph shown with an incidence matrix. e1 e2 e3 e4 e5 e6 edges v v v3 v v5 e1 e2 e3 e4 e5 e6 v1 v2 v3 v4 v5 vertices 7-Dec-18 Computer Science Department

44 Connectivity 7-Dec-18 Computer Science Department

45 Paths in Undirected Graphs
There is a path from vertex v0 to vertex vn if there is a sequence of edges from v0 to vn This path is labeled as v0,v1,v2,…,vn and has a length of m. The path is a circuit if the path begins and ends with the same vertex. A path is simple if it does not contain the same edge more than once. 7-Dec-18 Computer Science Department

46 Paths in Undirected Graphs Cont.
A path or circuit is said to pass through the vertices v0, v1, v2, …, vn or traverse the edges e1, e2, …, en. 7-Dec-18 Computer Science Department

47 Example 1 u1, u4, u2, u3 Is it simple? What is the length?
Does it have any circuits? u u2 u5 u u3 7-Dec-18 Computer Science Department

48 Example 2 u1, u5, u4, u1, u2, u3 Is it simple? What is the length?
Does it have any circuits? u u2 u u3 u4 7-Dec-18 Computer Science Department

49 Example 3 u1, u2, u5, u4, u3 Is it simple? What is the length?
Does it have any circuits? u u2 u u3 u4 7-Dec-18 Computer Science Department

50 Exercise Given the following graph and list of vertices, for each list determine if : It forms a path, if yes give the length Is simple any circuits list of vertices forms a path length simple circuits a,e,b,c,b. e,b,a,d,b,e. c,b,d,a,e,c. 7-Dec-18 Computer Science Department

51 Connectedness Theorem
An undirected graph is called connected if there is a path between every pair of distinct vertices of the graph. Theorem There is a simple path between every pair of distinct vertices of a connected undirected graph. 7-Dec-18 Computer Science Department

52 Example Are the following graphs connected? …... …... c e f a d b g e
7-Dec-18 Computer Science Department

53 Exercise ………… Determine whether the given graphs are connected.
7-Dec-18 Computer Science Department

54 Connectedness (Cont.) A graph that is not connected is the union of two or more disjoint connected subgraphs called the connected components of the graph. 7-Dec-18 Computer Science Department

55 Example What are the connected components of the following graph? b d
7-Dec-18 Computer Science Department

56 Example Cont. What are the connected components of the following graph? b a c d e h g f {a, b, c}, {d, e}, {f, g, h} 7-Dec-18 Computer Science Department

57 Connectedness in Directed Graphs
A directed graph is strongly connected if there is a directed path between every pair of vertices. A directed graph is weakly connected if there is a path between every pair of vertices in the underlying undirected graph. 7-Dec-18 Computer Science Department

58 Example 1 Is the following graph strongly connected? Is it weakly connected? This graph is strongly connected. Why? Because there is a directed path between every pair of vertices. If a directed graph is strongly connected, then it must also be weakly connected. a b c e d 7-Dec-18 Computer Science Department

59 Example 2 Is the following graph strongly connected? Is it weakly connected? a b c e d This graph is not strongly connected. Why not? Because there is no directed path between a and b, a and e, etc. However, it is weakly connected. (Imagine this graph as an undirected graph.) 7-Dec-18 Computer Science Department

60 Exercise weakly connected weakly connected
Determine whether each of these graphs is strongly connected and if not, whether it is weakly connected. weakly connected weakly connected 7-Dec-18 Computer Science Department

61 Conclusion In this chapter we have covered:
Introduction to Graphs Graph Terminology Representing Graphs Graph Connectivity Refer to chapter 9 of the book for further reading. 7-Dec-18 Computer Science Department


Download ppt "CS100: Discrete structures"

Similar presentations


Ads by Google