Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 103 Discrete Structures Lecture 20

Similar presentations


Presentation on theme: "CS 103 Discrete Structures Lecture 20"— Presentation transcript:

1 CS 103 Discrete Structures Lecture 20
Graphs (1) Chapter 1 section 1.1 by Dr. Mosaad Hassan

2 Second Midterm Exam 1st Lecture in December (same time as the lecture)
75 minute duration Will cover all lectures delivered before the exam date Will consist of MCQ’s, fill-in-the-blanks, questions with short answers, writing of proofs, and drawing of diagrams If you miss this exam for any reason, you will have to appear for a makeup exam on the Thursday of the last week of teaching. That exam will cover all lectures delivered in the semester. It will consist of writing of proofs, drawing of diagrams and answering questions having page answers.

3 Graphs Chapter 10

4 Chapter Summary Graphs and Graph Models
Graph Terminology and Special Types of Graphs Representing Graphs and Graph Isomorphism Connectivity

5 Graphs and Graph Models
Section 10.1

6 Section Summary Introduction to Graphs Graph Taxonomy Graph Models

7 Graphs A graph G = (V, E) consists of V, a nonempty set of vertices (or nodes), and E, a set of edges Each edge has either 1 or 2 vertices associated with it, called its endpoints. An edge is said to connect its endpoints A graph with an infinite V (i.e. consisting of an infinite number of vertices) is called an infinite graph A graph with a finite V is called a finite graph. We will focus on finite graphs

8 How many vertices? How many edges?
Graphs: Example Suppose that a network is made up of data centers and communication links between computers. We can represent the location of each data center by a vertex and each communications link by an edge Note: We have a lot of freedom when we draw a graph. All that matters is the connections made by the edges, not the particular geometry depicted. For example, the lengths of edges, whether edges cross, how vertices are depicted, and so on, do not matter Denver New York Chicago Washington Detroit How many vertices? How many edges? San Francisco Los Angeles

9 Graphs: Example (contd.)
Another way of depicting the graph on the previous slide: V = {Chicago, Denver, Detroit, Los Angeles, New York, San Francisco, Washington} E = {{San Francisco, Los Angeles}, {San Francisco, Denver}, {Los Angeles, Denver}, {Denver, Chicago}, {Chicago, Detroit}, {Detroit, New York}, {New York, Washington}, {Chicago, Washington}, {Chicago, New York}}

10 Simple Graphs A graph is a simple graph if
each edge connects 2 different vertices no 2 edges connect the same pair of vertices In a simple graph each edge is associated with an unordered pair of vertices and no other edge is associated with that pair San Francisco Los Angeles Denver New York Chicago Washington Detroit

11 Multigraphs Graphs that may have multiple edges connecting the same pair of vertices are called multigraphs San Francisco Denver Los Angeles New York Chicago Washington Detroit

12 Pseudographs Pseudographs are graphs that include loops
Loops are edges that connect a vertex to itself Pseudographs may include multiple edges as well San Francisco Denver Los Angeles New York Chicago Washington Detroit

13 Multiple Edges Allowed?
Type Multiple Edges Allowed? Loops Allowed? Simple graphs No Multigraphs Yes Pseudographs

14 Undirected Graphs The graphs we have introduced so far are undirected graphs Their edges are undirected, i.e. do not include arrowheads. Each edge is associated with an unordered pair of vertices San Francisco Denver Los Angeles New York Chicago Washington Detroit

15 Directed Graphs A directed graph (or digraph) G(V, E) consists of a nonempty set of vertices V and a set of directed edges (or arcs) E 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 vertex u and end at vertex v Detroit San Francisco Denver Los Angeles New York Chicago Washington

16 Simple Directed Graph When a directed graph has no loops or multiple directed edges, it is called a simple directed graph

17 Directed Multigraphs When a directed graph includes multiple directed edges or loops, it is called a directed multigraph When there are m directed edges, each associated to an ordered pair of vertices (u, v), we say that (u, v) is an edge of multiplicity m

18 Mixed Graph A graph with both directed and undirected edges is called a mixed graph

19 Graph Terminology: Summary
To understand the structure of a graph, we ask these questions: Are the edges of undirected or directed (or both)? If the edges are undirected, are multiple edges present that connect the same pair of vertices? If the edges are directed, are multiple directed edges present? Are loops present?

20 Graph Models: Computer Networks
When we build a graph model, we use the appropriate type of graph to capture the important features of the application We illustrate this process using graph models of different types of computer networks. In these models, the vertices represent data centers and the edges represent communication links To model a computer network where we are only concerned whether two data centers are connected by a communications link, we use a simple graph. This is the appropriate type of graph when we only care whether two data centers are directly linked (and not how many links there may be) and all links work in both directions

21 Graph Models: Computer Networks
To model a computer network where we care about the number of links between data centers, we use a multigraph To model a computer network with diagnostic links at data centers, we use a pseudograph, as loops are needed To model a network with multiple one-way links, we use a directed multigraph

22 Other Applications of Graphs
We will illustrate how graph theory can be used in models of: Social networks Communications networks Information networks Software design Transportation networks It’s a challenge to find a subject to which graph theory has not yet been applied

23 Graph Models: Social Networks
Graphs can be used to model social structures based on different kinds of relationships between people or groups In a social network, vertices represent individuals or organizations and edges represent their relationships Useful graph models of social networks include: Friendship Graphs - undirected graphs where two people are connected if they are friends (in the real world, on Facebook, or in a particular virtual world, and so on.) Influence Graphs - directed graphs where there is an edge from one person to another if the 1st person can influence the 2nd person

24 Applications to Information Networks
Graphs can be used to model different types of networks that link different types of information For example, in a web graph, web pages are represented by vertices and links are represented by directed edges A web graph models the web at a particular time More on how the web graph is used by search engines is discussed in Section 11.4

25 Transportation Graphs
Graph models are extensively used in the study of transportation networks. Airline networks can be modeled using directed multigraphs where airports are represented by vertices each flight is represented by a directed edge from the vertex representing the departure airport to the vertex representing the destination airport Road networks can be modeled using graphs where vertices represent intersections and edges represent roads undirected edges represent two-way roads and directed edges represent one-way roads

26 Software Design Applications
Graph models are extensively used in software design. We will introduce here the model representing the dependency between the modules of a software application In software design, the system is divided into modules, each performing a specific task. We use a module dependency graph to represent the dependency between these modules. These dependencies need to be understood before coding can be done. In a module dependency graph vertices represent software modules and there is an edge from one module to another if the second module depends on the first

27 Graph Terminology and Special Types of Graphs
Section 10.2

28 Section Summary Basic Terminology Some Special Types of Graphs
Bipartite Graphs Bipartite Graphs and Matchings Some Applications of Special Types of Graphs New Graphs from Old

29 Graph Terminology Two vertices u and v in an undirected graph G are called adjacent in G if u and v are endpoints of an edge of G If e is associated with {u, v}, the edge e is called incident with the vertices u and v. The edge e is also said to connect u and v 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 the vertex v is denoted by deg(v)

30 Degree of a Vertex: Example
b c d c e a f e g deg(a) = 2 deg(b) = deg(c) = deg(f) = 4 deg(d) = 1 deg(e) = 3 deg(g) = 0 deg(a) = 4 deg(b) = deg(e) = 6 deg(c) = 1 deg(d) = 5

31 The Handshaking Theorem
Theorem 1: Let G = (V, E) be a undirected graph. Then 2 𝐸 = 𝑣∈𝑉 𝑑𝑒𝑔 𝑣 Proof: Each edge contributes twice to the degree count of all vertices. Hence, both the left-hand and right- hand sides of this equation equal twice the number of edges Example 1: How many edges are there in a graph with 10 vertices each of degree 6? Sum of the degrees of the vertices = 6 · 10 = 60  2|E| = 60  |E| = 30

32 The Handshaking Theorem
Example 2 : If a graph has 5 vertices, can each vertex have degree 3? This is not possible by the handshaking theorem, because the sum of the degrees of the vertices 3 · 5 = 15 is odd Theorem 2: An undirected graph has an even number of vertices of odd degree

33 Directed Graph Terminology
When (u, v) is a directed edge, u is said to be adjacent to v and v is said to be adjacent from u Vertex u is called the initial or start vertex of (u, v) Vertex v is called the terminal or end vertex of (u, v) The start vertex and end vertex of a loop are the same

34 In-degree and Out-degree
In a directed graph the in-degree of a vertex v, denoted by deg-(v), is the number of edges with v as their start vertex The out-degree of v, denoted by deg+(v), is the number of edges with v as their end vertex A loop at a vertex contributes 1 to both the in-degree and the out-degree of this vertex Theorem: Let G = (V, E) be a graph with directed edges. Then

35 In-degree and Out-degree: Example
deg-(a) = 2, deg-(b) = 2 deg-(c) = 3, deg-(d) = 2 deg-(e) = 3, deg-(f) = 0 deg+(a) = 4, deg+(b) = 1 deg+(c) = 2, deg+(d) = 2 deg+(e) = 3, deg+(f) = 0 f

36 Complete Graphs The complete graph on n vertices, Kn , is the simple graph that contains exactly 1 edge between each pair of distinct vertices, i.e. every node is adjacent to every other node u  V, v  V : u  v  {u, v}E Kn has n vertices and n(n - 1)/2 edges

37 Cycles The cycle Cn , n  3, consists of n vertices v1 , v2 , , vn and edges {v1 , v2}, {v2 , v3}, …, {vn-1, vn}, and {vn , v1} Cn has n vertices and n edges

38 Wheels We obtain the wheel Wn when we add an additional vertex to the cycle Cn , n  3, and connect this new vertex to each of the n vertices in Cn , by new edges Wn has n vertices and 2n edges

39 n-Cubes The n-dimensional hypercube, or n-cube, denoted by Qn is the graph that has vertices representing the 2n- bit strings of length n. Vertices are adjacent iff the bit strings that they represent differ in exactly 1 bit position Q Q Q3 Qn has 2n vertices and n2n - 1 edges 110 111 10 11 100 101 010 011 1 00 01 000 001

40 Bipartite Graphs A simple graph G is bipartite if V can be partitioned into two disjoint subsets V1 and V2 such that every edge connects a vertex in V1 and a vertex in V2. In other words, there are no edges which connect two vertices in V1 or in V2

41 Complete Bipartite Graphs
A complete bipartite graph Km,n is a graph that has its vertex set partitioned into two subsets V1 of size m and V2 of size n such that there is an edge from every vertex in V1 to every vertex in V2 Km,n has m + n vertices and m · n edges

42 CS 103 Discrete Structures Lecture 21
Graphs (2) Chapter 1 section 1.1 by Dr. Mosaad Hassan

43 Second Midterm Exam 1st Lecture in December (same time as the lecture)
75 minute duration Will cover all lectures delivered before the exam date Will consist of MCQ’s, fill-in-the-blanks, questions with short answers, writing of proofs, and drawing of diagrams If you miss this exam for any reason, you will have to appear for a makeup exam on the Thursday of the last week of teaching. That exam will cover all lectures delivered in the semester. It will consist of writing of proofs, drawing of diagrams and answering questions having page answers.

44 Graphs for Computer Network Architecture
Some local area networks use a star topology, which is a complete bipartite graph K1,n ,as shown in (a). All devices are connected to a central controller Other local networks are based on a ring topology, where each device is connected to exactly two others using Cn ,as illustrated in (b) Some use a wheel Wn topology, combining the features of both star and ring topologies Various special graphs also play a role in parallel processing where processors need to be interconnected as one processor may need the output generated by another A common way to connect processors in parallel is the mesh network, illustrated here for 16 processors The n-cube, Qn, is another way to connect processors in parallel, e.g., Intel Hypercube

45 New Graphs from Old: Subgraphs
A subgraph of a graph G = (V, E) is a graph (W, F), where W ⊆ V and F ⊆ E. A subgraph H of G is a proper subgraph of G if H ≠ G Example: Here we show K5 and one of its subgraphs

46 New Graphs from Old: Unions
The union of two simple graphs G1 = (V1 , E1) and G2 = (V2 , E2) is the simple graph with vertex set V1 ⋃ V2 and edge set E1 ⋃ E2. The union of G1 and G2 is denoted by G1 ⋃ G2

47 Representing Graphs and Graph Isomorphism
Section 10.3

48 Section Summary Adjacency Lists Adjacency Matrices Incidence Matrices
Isomorphism of Graphs

49 Representing Graphs: Adjacency List
One way to represent a graph without multiple edges is to list all the edges of that graph Another way to represent a graph with no multiple edges is to use adjacency lists, which specify the vertices that are adjacent to each vertex of the graph Adjacency List Vertex Adjacent Vertices a b, c, e b a c a, d, e d c, e e a, c, d b c a e d

50 Adjacency List for Directed Graphs
Adjacency List for a Directed Graph Initial vertex Terminal vertices a b, c, d, e b b, d c a, c, e d e b, c, d d e

51 Representing Graphs: Adjacency Matrices
Suppose that G = (V, E) is a simple graph where |V| = n and that the vertices of G are listed arbitrarily as v1 , v2 ,..., vn The adjacency matrix A of G, AG, with respect to this listing of the vertices, is the n  n zero-one matrix with 1 as its (i, j)th entry when vi and vj are adjacent, and 0 as its (i, j)th entry when they are not adjacent In other words, if its adjacency matrix is A = [aij], then

52 Adjacency Matrices: Simple Graphs
When a graph is sparse, that is, it has few edges relatively to the total number of possible edges, it is much more efficient to represent the graph using an adjacency list than an adjacency matrix But for a dense graph, which includes a high percentage of possible edges, an adjacency matrix is preferable The ordering of vertices is a, b, c, d The ordering of vertices is a, b, c, d Note: The adjacency matrix of a simple graph is symmetric, i.e., aij = aji . Also, since there are no loops, each diagonal entry aii for i = 1, 2, 3, …, n, is 0

53 Adjacency Matrices: Pseudographs
A loop at the vertex vi is represented by a 1 at the (i, j)th position of the matrix When multiple edges connect the same pair of vertices vi and vj, (or if multiple loops are present at the same vertex), the (i, j)th entry equals the number of edges connecting the pair of vertices Adjacency matrix using the ordering of vertices a, b, c, d

54 Adjacency Matrices: Directed Graphs
The matrix for a directed graph G = (V, E) has a 1 in its (i, j)th position if there is an edge from vi to vj, where v1, v2, … vn is a list of the vertices In other words, if the graphs adjacency matrix is AG = [aij], then The adjacency matrix for a directed graph does not have to be symmetric, because there may not be an edge from vi to vj, when there is an edge from vj to vi To represent directed multigraphs, the value of aij is the number of edges connecting vi to vj

55 Representing Graphs: Incidence Matrices
Let G = (V, E) be an undirected graph Suppose that v1, v2,..., vn are the vertices and e1, e2,…, em are the edges of G Then the incidence matrix with respect to this ordering of V and E is the n  m matrix M = [mij], where

56 Incidence Matrices: Simple Graph
e e e e e e6

57 Incidence Matrices: Pseudographs
Multiple edges are represented in the incidence matrix using columns with identical entries, because these edges are incident with the same pair of vertices Loops are represented using a column with exactly one entry equal to 1, corresponding to the vertex that is incident with this loop v3 v5 e8 e e e e e e e e8

58 Graph Isomorphism To discuss graph isomorphism, we first need to understand 1-to-1 and onto functions

59 1-to-1 and Onto Functions
A function f is an assignment from set A to set B of exactly 1 element of A to each element of B. We write f(a) = b if b is the unique element of B assigned by the function f to the element a of A. A function f is said to be one-to-one iff f(a) = f(b) implies that a = b for all a and b in the domain. These functions never assign the same value to 2 different domain elements. A function f from A to B is called onto iff for every element b  B there is an element a  A with f(a) = b. Every element of B is an image of some element of A

60 1-to-1 and Onto Functions
not onto onto, not 1-to-1 1-to-1, and onto neither 1-to-1, nor onto not a function

61 Graph Isomorphism The simple graphs G = (VG , EG) and H = (VH , EH) are isomorphic if there exists a 1-to-1 and onto function f from VG to VH with the property that a and b are adjacent in G iff f(a) and f(b) are adjacent in H, a,b VG. Such a function f is called an isomorphism Isomorphic graphs may look dissimilar, but actually are the same Two simple graphs that are not isomorphic are called non-isomorphic

62 Graph Isomorphism: Example
The function f with f(u1) = v1, f(u2) = v4, f(u3) = v3, and f(u4) = v2 is a 1-to-1 correspondence between VG and VH To see that this correspondence preserves adjacency, note that adjacent vertices in G are: u1 and u2 u1 and u3 u2 and u4 u3 and u4 and each of the pairs f(u1) = v1 and f(u2) = v4 f(u1) = v1 and f(u3) = v3 f(u2) = v4 and f(u4) = v2 f(u3) = v3 and f(u4) = v2 are adjacent in H

63 How to Check for Isomorphism?
Difficult to determine if 2 simple graphs are isomorphic There are n! possible 1-to-1 correspondences between the vertex sets of 2 simple graphs with n vertices Sometimes it is easier to show that 2 graphs are not isomorphic In particular, we can show that 2 graphs are not isomorphic if we can find a property only 1 of the 2 graphs has, but that is preserved by isomorphism

64 Graph Invariants A property preserved by isomorphism of graphs is called a graph invariant. For example, isomorphic graphs must have: The same number of vertices The same number of edges The degrees of the vertices in the 2 graphs must be the same If any of these differ in 2 simple graphs, the graphs are non-isomorphic If they are the same for 2 simple graphs, it does not necessarily mean that the graphs are isomorphic

65 Checking for Isomorphism: Example 1
Show that these graphs are not isomorphic Both G and H have 5 vertices and 6 edges However, H has a vertex of degree 1, namely, e, whereas G has no vertices of degree 1 It follows that G and H are not isomorphic

66 Checking for Isomorphism: Example 2
Both graphs have 8 vertices and 10 edges They also both have 4 vertices of degree 2 and 4 of degree 3 Because these invariants all agree, they may be isomorphic

67 Checking for Isomorphism: Example 2
But, they are not isomorphic To see this, note that because deg(a) = 2 in G, a must correspond to either t, v, x, or y in H, because these are the vertices of degree 2 in H However, each of these 4 vertices in H is adjacent to another vertex of degree 2 in H, which is not true for a in G

68 Checking for Isomorphism: Example 2
Another way to see that G and H are not isomorphic is to note that the subgraphs of G and H made up of vertices of degree 3 and the edges connecting them must be isomorphic if these 2 graphs are isomorphic Those subgraphs are not isomorphic, therefore G and H are not isomorphic

69 CS 103 Discrete Structures Lecture 22
Graphs (3) Chapter 1 section 1.1 by Dr. Mosaad Hassan

70 Second Midterm Exam 1st Lecture in December (same time as the lecture)
75 minute duration Will cover all lectures delivered before the exam date Will consist of MCQ’s, fill-in-the-blanks, questions with short answers, writing of proofs, and drawing of diagrams If you miss this exam for any reason, you will have to appear for a makeup exam on the Thursday of the last week of teaching. That exam will cover all lectures delivered in the semester. It will consist of writing of proofs, drawing of diagrams and answering questions having page answers.

71 Checking for Isomorphism: Example 3
Both G and H have 6 vertices and 7 edges. Both have 4 vertices of degree 2 and 2 vertices of degree 3 It is also easy to see that the subgraphs of G and H consisting of all vertices of degree 2 and the edges connecting them are isomorphic Because G and H agree with respect to these invariants, it is reasonable to try to find an isomorphism f

72 Checking for Isomorphism: Example 3
We now will define a function f and then determine whether it is an isomorphism Because deg(u1) = 2 and u1 is not adjacent to any other vertex of degree 2, the image of u1 must be either v4 or v6, the only vertices of degree 2 in H not adjacent to a vertex of degree 2 We arbitrarily set f(u1) = v6 If this choice did not lead to isomorphism, we would then try f(u1) = v4

73 Checking for Isomorphism: Example 3
As u2 is adjacent to u1, the possible images of u2 are v3 and v5 We arbitrarily set f(u2) = v3 Continuing in this way, using adjacency of vertices and degrees as a guide, we set f(u3) = v4 f(u4) = v5 f(u5) = v1 f(u6) = v2

74 Checking for Isomorphism: Example 3
We now have a 1-to-1 correspondence between the vertex set of G and the vertex set of H, namely, f(u1) = v6 f(u2) = v3 f(u3) = v4 f(u4) = v5 f(u5) = v1 f(u6) = v2

75 Checking for Isomorphism: Example 3
To see whether f preserves edges, we examine AG and AH with the rows and columns labeled by the images of the corresponding vertices in G Because AG = AH, it follows that f preserves edges As we have a 1-to-1 correspondence between VG and VH, and AG = AH, we conclude that f is an isomorphism, so G and H are isomorphic

76 Applications of Graph Isomorphism
Chemists use molecular graphs to model chemical compounds. Vertices represent atoms and edges represent chemical bonds. When a new compound is synthesized, a database of molecular graphs is checked to determine whether the graph representing the new compound is isomorphic to the graph of a compound that this already known Electronic circuits are modeled as graphs in which the vertices represent components and the edges represent connections between them. Graph isomorphism is the basis for the verification that a particular layout of a circuit corresponds to the design’s original schematics determining whether a chip from one vendor includes the intellectual property of another vendor

77 Connectivity Section 10.4

78 Section Summary Paths Connectedness in Undirected Graphs
Connectedness in Directed Graphs

79 Paths in Undirected Graphs
In an undirected graph, a path of length n, n Z+, from u to v is a sequence of adjacent edges going from vertex u to vertex v A path is a circuit if u = v and n  0 A path traverses the vertices along it A path/circuit is simple if it contains no edge more than once Simple path: a, d, c, f, e The edges are {a, d}, {d, c}, {c, f }, {f, e}. Path length = 4 Circuit: b, c, f, e, b The edges are {b, c}, {c, f }, {f, e}, {e, b}. Path length = 4 Not a path: d, e, c, a because {e, c} is not an edge Not a simple path: a, b, e, d, a, b because {a, b} appears twice. Path length = 5

80 Paths in Directed Graphs
Same as in undirected graphs, but the path must go in the direction of the arrows, e.g. simple path a, b, c a b d c

81 Connected Undirected Graphs
An undirected graph is called connected if there is a path between every pair of distinct vertices of the graph Connected graph Disconnected graph (no path between a and f, for example)

82 Connected Components of a Graph
A connected component of a graph G is a connected subgraph of G that is not a proper subgraph of another connected subgraph of G A graph G that is not connected has two or more connected components that are disjoint and have G as their union The graph H is the union of 3 disjoint subgraphs H1, H2, and H3, none of which are proper subgraphs of a larger connected subgraph of G. These 3 subgraphs are the connected components of H

83 Strongly/Weakly Connected Directed Graphs
Strongly connected directed graph if there is a path from a to b and from b to a whenever a and b are vertices in the graph Weakly connected directed graph if there is a path between every 2 vertices of the graph when the direction of edges are disregarded

84 Strongly & Weakly Connected Graphs: Example
b d a b d c c Strongly connected directed graph Weakly connected directed graph (no directed path from a to b)

85 Section 10.1: Exercises For Exercises 3, 5, and 7, determine:
Whether the graphs shown has directed or undirected edges Whether it has multiple edges, and whether it has one or more loops Use your answers to determine the type of graph For each undirected graph that is not simple, find a set of edges to remove to make it simple

86 Section 10.2: Exercises Find the sum of degrees of each graph in Exercise 1, 2, and 3, and verify that it equals twice the number of edges in the graph 37. The following graph has 4 vertices. Draw 5 subgraphs of this graph that have 3 vertices

87 Section 10.3: Exercises 3. Use an adjacency list and adjacency matrix to represent this graph. 4. Draw graphs having the following adjacency matrices. 40. Are the simple graphs with the following adjacency matrices isomorphic? ,

88 Section 10.4: Exercises 1. Does each of these lists of vertices form a path in the this graph? Which paths are simple? Which are circuits? What are the lengths of those that are paths? a, b, e, c, b a, d, a, d, a a, d, b, e, a a, b, e, c, b, d, a 2. Is this graph strongly connected? If not, is it weakly connected? 3. What is the length of the shortest path from e to b?


Download ppt "CS 103 Discrete Structures Lecture 20"

Similar presentations


Ads by Google