CS100: Discrete structures

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

CSE 211 Discrete Mathematics
Lecture 5 Graph Theory. Graphs Graphs are the most useful model with computer science such as logical design, formal languages, communication network,
1 Slides based on those of Kenneth H. Rosen Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Graphs.
Discrete Mathematics and Its Applications
1 Section 8.2 Graph Terminology. 2 Terms related to undirected graphs Adjacent: 2 vertices u & v in an undirected graph G are adjacent (neighbors) in.
Selected Topics in Data Networking Graph Representation.
Applied Discrete Mathematics Week 12: Trees
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE Discrete.
Let us switch to a new topic:
Graphs Rosen 8.1, 8.2. There Are Many Uses for Graphs! Networks Data organizations Scene graphs Geometric simplification Program structure and processes.
9.2 Graph Terminology and Special Types Graphs
GRAPH Learning Outcomes Students should be able to:
Graphs Chapter 10.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 9 (Part 1): Graphs  Introduction to Graphs (9.1)
Graph Theoretic Concepts. What is a graph? A set of vertices (or nodes) linked by edges Mathematically, we often write G = (V,E)  V: set of vertices,
1 Graphs Chapters 9.1 and 9.2 University of Maryland Chapters 9.1 and 9.2 Based on slides by Y. Peng University of Maryland.
Module #19: Graph Theory: part I Rosen 5 th ed., chs. 8-9 내년 3 월 ? 교환 학생 프로그램 영어 점수 미리미리 준비하세요.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 9 (Part 2): Graphs  Graph Terminology (9.2)
9.2: Graph Terminology. Special Simple Graphs Complete GraphsK 1,… CyclesC 3,… WheelsW 3,… N-cubesQ 1,… Complete bipartiteK 2,2,…
1 CS104 : Discrete Structures Chapter V Graph Theory.
9.1 Introduction to Graphs
Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements.
9 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 one or two vertices associated.
CS 103 Discrete Structures Lecture 20
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 9 (Part 1): Graphs  Introduction to Graphs (9.1)
Graphs 9.1 Graphs and Graph Models أ. زينب آل كاظم 1.
Basic properties Continuation
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Introduction to Graphs Slides by Gene Boggess
Graphs Basic properties.
1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.
Chapter 9: Graphs.
Graphs Rosen, Chapter 8. NOT ONE OF THESE! One of these!
Chap 7 Graph Def 1: Simple graph G=(V,E) V : nonempty set of vertices E : set of unordered pairs of distinct elements of V called edges Def 2: Multigraph.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
1 Graphs Chapters 10.1 and 10.2 University of Maryland Chapters 10.1 and 10.2 Based on slides by Y. Peng University of Maryland.
Chapter Chapter Summary Graphs and Graph Models Graph Terminology and Special Types of Graphs Representing Graphs and Graph Isomorphism Connectivity.
An Introduction to Graph Theory
Chapter 9 (Part 1): Graphs
Applied Discrete Mathematics Week 14: Trees
Applied Discrete Mathematics Week 13: Graphs
Chapter 9 (Part 2): Graphs
Let us switch to a new topic:
Graphs Rosen, Chapter 8.
Lecture 19: CONNECTIVITY Sections
Applied Discrete Mathematics Week 13: Graphs
Special Graphs By: Sandeep Tuli Astt. Prof. CSE.
Copyright © Zeph Grunschlag,
Graph Graphs and graph theory can be used to model:
Graphs Hubert Chan (Chapter 9) [O1 Abstract Concepts]
COT 3100, Spring 2001 Applications of Discrete Structures
Chapters 8.1 and 8.2 Based on slides by Y. Peng University of Maryland
CS 250, Discrete Structures, Fall 2015
Graphs Rosen, Chapter 8.
Agenda Lecture Content: Introduction to Graph Path and Cycle
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Graphs Slides are adopted from “Discrete.
Graphs Chapters 10.1 and 10.2 Based on slides by Y. Peng University of Maryland.
Graphs.
Graphs.
Based on slides by Y. Peng University of Maryland
Chapter 13 (Part 1): Graphs
Rosen 5th ed., chs. 8-9 ~44 slides (more later), ~3 lectures
Chapters 8.1 and 8.2 Based on slides by Y. Peng University of Maryland
Let us switch to a new topic:
Graphs.
Applied Discrete Mathematics Week 13: Graphs
Based on slides by Y. Peng University of Maryland
Presentation transcript:

CS100: Discrete structures Computer Science Department Lecture 7: Graphs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Graph Terminology 7-Dec-18 Computer Science Department

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Bipartite Graph : Example 1 1 2 6 3 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

Bipartite Graph : Example 2 1 2 3 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

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

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

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

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

Representing Graphs 7-Dec-18 Computer Science Department

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

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

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

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

Connectivity 7-Dec-18 Computer Science Department

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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