Chapter 9: Graphs.

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

CSE 211 Discrete Mathematics
CSE 211 Discrete Mathematics
Chapter 9 Graphs.
Lecture 5 Graph Theory. Graphs Graphs are the most useful model with computer science such as logical design, formal languages, communication network,
22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
22C:19 Discrete Math Graphs Fall 2014 Sukumar Ghosh.
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
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Applied Discrete Mathematics Week 12: Trees
Graph & BFS.
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.
Discrete Structures Chapter 7A Graphs Nurul Amelina Nasharuddin Multimedia Department.
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.
22C:19 Discrete Math Graphs Spring 2014 Sukumar Ghosh.
9.2 Graph Terminology and Special Types Graphs
GRAPH Learning Outcomes Students should be able to:
Intro to Graphs CSIT 402 Data Structures II. CSIT 402 Graph Introduction2 Graphs Graphs are composed of ›Nodes (vertices) Can be labeled ›Edges (arcs)
Graphs Chapter 10.
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.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
16.1 CompSci 102© Michael Frank Today’s topics GraphsGraphs –Basics & types –Properties –Connectivity –Hamilton & Euler Paths Reading: Sections Reading:
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.
Lecture 10: Graphs Graph Terminology Special Types of Graphs
© 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 THEROY. 2 –Graphs Graph basics and definitions Vertices/nodes, edges, adjacency, incidence Degree, in-degree, out-degree Subgraphs, unions, isomorphism.
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.
Graphs What are Graphs? General meaning in everyday math: A plot or chart of numerical data using a coordinate system. Technical meaning in discrete.
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.
COSC 2007 Data Structures II Chapter 14 Graphs I.
September1999 CMSC 203 / 0201 Fall 2002 Week #13 – 18/20/22 November 2002 Prof. Marie desJardins.
Chapter 5 Graphs  the puzzle of the seven bridge in the Königsberg,  on the Pregel.
1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian.
CS 103 Discrete Structures Lecture 20
Graphs 9.1 Graphs and Graph Models أ. زينب آل كاظم 1.
And before you really hate (mathematical) relations and begin to break your (social) relations, let’s switch to a new topic: Graphs Discrete Structures.
Basic properties Continuation
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Introduction to Graphs Slides by Gene Boggess
1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.
Chapter Graphs and Graph Models
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
Let us switch to a new topic:
Applied Discrete Mathematics Week 13: Graphs
Graph Graphs and graph theory can be used to model:
COT 3100, Spring 2001 Applications of Discrete Structures
Chapters 8.1 and 8.2 Based on slides by Y. Peng University of Maryland
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 All tree structures are hierarchical. This means that each node can only have one parent node. Trees can be used to store data which has a definite.
Chapters 8.1 and 8.2 Based on slides by Y. Peng University of Maryland
CS100: Discrete structures
Let us switch to a new topic:
Presentation transcript:

Chapter 9: Graphs

9.1 Graphs and Graph Models Definition 1: 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 with it, called its endpoints. An edge is said to connect its endpoints. Remark: The set of vertices V of a graph G may be infinite. A graph with an infinite vertex set is called an infinite graph, and in comparison, a graph with a finite vertex set is called a finite graph. In this course we will usually consider only finite graphs. (c)2001-2002, Michael P. Frank

Summary It is a pair G = (V, E ), where Example: V = V (G ) = Set of vertices E = E (G ) = Set of edges Example: V = {s, u, v, w, x, y, z} E = {(x, s), (x, v)1, (x, v)2, (x, u), (v, w), (s, v), (s, u), (s, w), (s, y), (w, y), (u, y), (u, z), (y, z)}

Example This computer network can be modeled using a graph in which the vertices of the graph represent the data centers and the edges represent communication links.

Simple Graphs A graph in which each edge connects two different vertices and where no more than one edge connect the same pair of vertices is called a simple graph. e.g. The graph in figure 1 is an example of a simple graph.

Multigraphs A computer network may contain multiple links between data centers, as shown in Figure 2. To model such networks we need graphs that have more than one edge connecting the same pair of vertices. Graphs that may have multiple edges connecting the same vertices are called multigraphs.

Pseudographs Sometimes a communication link connects a data center with itself. To model this network we need to include edges that connect a vertex to itself. Such edges are called loops. Graphs that may include loops, and possibly multiple edges are sometimes called pseudographs.

Directed Graphs Definition 2: A directed graph (or digraph) (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 u and end at v. When a directed graph has no loops and has no multiple directed edges, it is called a simple directed graph.

Simple Directed Graph

Directed Multigraph Directed graphs that may have multiple directed edges from a vertex to a second (possibly the same) vertex are to used model such networks. We call such graphs directed multigraphs.

(c)2001-2002, Michael P. Frank

9.2: Graph Terminology Adjacent, connects, endpoints, degree, initial, terminal, in-degree, out-degree, complete, complete bipartite, cycles, wheels, n-cubes.

Undirected Graph: Adjacency Let G be an undirected graph with edge set E. Let e  E where e = {u ,v}. We say that: The vertices u and v are adjacent / neighbors / connected. The edge e is incident with vertices u and v. The edge e connects u and v. The vertices u and v are endpoints of the edge e.

Undirected Graph: Degree of a Vertex Let G be an undirected graph, v V a vertex. The degree of v, deg(v), is its number of incident edges. (Except that any self-loops are counted twice.) A vertex with degree 0 is isolated. A vertex of degree 1 is pendant.

Handshaking Theorem Let G = (V, E ) be an undirected (simple, multi- or pseudo-) graph with e edges. Then:

Example How many edges are there in a graph with ten vertices each of degree 6? Solution: Sum of the degrees of the vertices 6×10 = 60. Therefore: 60 = 2|E| , |E| = 30

deg(a ) = 6 deg(b ) = 4 deg(c ) = 1 pendant deg(d ) = 0 isolated deg(e ) = 3 deg(f ) = 4 deg(g ) = 2 ∑deg(v ) = 20 = 2 (10) = 2 ∑edges

Directed Graph: Adjacency Let G be a directed (possibly multi-) graph, and let e be an edge of G that is (u ,v). Then we say: u v u is adjacent to v, v is adjacent from u e comes from u, e goes to v. e connects u to v, e goes from u to v The initial vertex of e is u The terminal vertex of e is v

Directed Graph: Degree of a vertex Let G be a directed graph and v a vertex of G. The in-degree of v, deg(v), is the number of edges going to v (v is terminal). The out-degree of v, deg(v), is the number of edges coming from v (v is initial). The degree of v, deg(v) = deg(v) + deg(v), is the sum of v’s in-degree and out-degree. A loop at a vertex contributes 1 to both in-degree and out-degree of this vertex.

Directed Handshaking Theorem Let G be a directed (possibly multi-) graph with vertex set V and edge set E. Then: Note that the degree of a node is unchanged by whether we consider its edges to be directed or undirected.

∑deg+ (v ) = ∑deg− (v ) = 1/2 ∑deg(v ) = ∑edges = 10 deg+(a ) = 3 deg−(a ) = 3 deg+(b ) = 3 deg−(b ) = 1 deg+(c ) = 0 deg−(c ) = 1 deg+(d ) = 0 deg−(d ) = 0 Deg+(e ) = 1 deg−(e ) = 2 Deg+(f ) = 2 deg−(f ) = 2 Deg+(g ) = 1 deg−(g ) = 1 ∑deg+ (v ) = ∑deg− (v ) = 1/2 ∑deg(v ) = ∑edges = 10

Special Graph Structures Special cases of undirected graph structures: Complete graphs: Kn Complete bipartite graphs: Km,n Cycles: Cn Wheels: Wn n-Cubes: Qn

Complete Graphs For any n  N, a complete graph on n vertices, Kn , is a simple graph with n nodes in which every node is adjacent to every other node: u , v V : u  v  {u , v}  E. K1 K2 K3 K4 K5 K6 Note that Kn has n vertices and edges.

Complete Bipartite Graphs The complete bipartite graph Km,n is the graph that has its vertex set partitioned into two subsets of m and n vertices such that there is an edge between vertices if and only if one vertix in the first set and the other vertix in the second set. K2,3 K3,5 Note that Km,n has m+n vertices and mn edges.

E = {{v1, v2}, {v2, v3}, …, {vn1, vn}, {vn , v1}}. Cycles For any n  3, a cycle on n vertices, Cn , is a simple graph where V = {v1,v2, … ,vn} and E = {{v1, v2}, {v2, v3}, …, {vn1, vn}, {vn , v1}}. C3 C4 C5 C6 C8 C7 Note that Cn has n vertices and n edges.

Wheels For any n  3, a wheel Wn , is a simple graph obtained by taking the cycle Cn and adding one extra vertex vhub and n extra edges {{vhub, v1}, {vhub, v2}, …, {vhub, vn}}. W3 W4 W5 W6 W7 W8 Note that Wn has n+1 vertices and 2n edges.

n -Cubes (Hypercubes) For any n  N, the hypercube Qn is a simple graph consisting of two copies of Qn-1 connected together at corresponding nodes. Q0 has 1 node. Q0 Q1 Q2 Q3 Q4 Note that Qn has 2n vertices and n2n − 1 edges.

9.3 Graph Representations Adjacency Lists. Adjacency Matrices. Incidence Matrices.

Undirected: Adjacency Lists A table with 1 row per vertex, listing its adjacent vertices. b a d c e f

Undirected: Adjacency Matrices Matrix A = [aij], where aij is 1 if {vi ,vj } is an edge of G, 0 otherwise. b a b c d e a c e d

Example 1 Draw a graph using the following adjacency matrix A with respect to the vertices: a, b, c, d : a b d c

Example 2 Find an adjacency matrix that represents the graph: a b c d

Example 3 Let A be the adjacency matrix of a graph G with vertices a, b, c, d . Find the degrees of the vertices of G. Answer: The degrees of the vertices a, b, c and d of G are 3, 2, 2 and 1, respectively.

Directed Adjacency Lists 1 row per node, listing the terminal nodes of each edge incident from that node. Initial vertex Terminal vertices V1 V2, V4, V5 V2 V4 V3 V5

Directed Adjacency Matrices Matrix A = [aij], where aij is 1 if {vi ,vj } is an edge of G, 0 otherwise. b a b c d e a c e d

Incidence Matrices It is a matrix A = [aij], where aij is 1 if the edge ej is incident with the vertex vi , 0 otherwise. e1 e2 e3 e4 e1 1 2 e2 e4 e3 3 4 5

Example Let A be the incident matrix of a graph G. Draw G. Let G = {V, E}, where V= {a, b, c, d} and E = {e1, e2, e3, e4, e5}. e2 a b e4 e3 e5 d c e1

9.4 Connectivity In an undirected graph, a path of length n 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. A path traverses the vertices along it. A path is simple if it contains no edge more than once.

Example: Simple path: a, d, c, f, e The edges are {a, d }, {d, c}, {c, f }, {f, e} Length = 4 Circuit: b, c, f, e, b The edges are {b, c},{c, f }, {f, e},{e, b} 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 Length = 5

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 d b c

Undirected Graphs: Connectedness An undirected graph is called connected if there is a path between every pair of distinct vertices of the graph. e.g. a b e a b c c d d e Connected Not connected (No path between a and c)

Connected Components a b g h f c d i e A graph that is not connected is the union of two or more connected subgraphs with no vertices in common. These disjoint connected subgraphs are called the connected components of the graph. a b g h f c d i e H1 H2 Graph H has three connected components

Directed Graphs: Connectedness Definition 1: A directed graph is strongly connected if there is a path from a to b and from b to a whenever a and b are vertices in the graph. Definition 2: A directed graph is weakly connected if there is a path between every two vertices when the direction of edges are disregarded.

Example (No directed path from a to b) Strongly connected weakly connected (No directed path from a to b) a b d a b d c c

9.6 Shortest-Path Problems Many problems can be modeled using graphs with weights assigned to their edges. As an illustration, consider how an airline system can be modeled. We set up the basic graph model by representing cities by vertices and flights by edges. Problems involving distances can be modeled Problems involving flight time by assigning distances between cities to the edges. can be modeled by assigning flight times to edges. Problems involving fares can be modeled by assigning fares to the edges. Graphs that have a number assigned to each edge are called weighted graphs.

Example Flight mileage

Example Flight times

Example Flight Fares

Question What is a shortest path, that is, a path of least length, between two given vertices? For instance, in the airline system represented by the weighted graph shown in Figure 1 what is a shortest path in air distance between Boston and Los Angeles? What combinations of flights has the smallest total flight time (that is, total time in the air, not including time between flights) between Boston and Los Angeles? What is the cheapest fare between these two cities?

Example What is the shortest path from a to z in the figure Path length a b c z 4 + 3 + 2 = 9 a b e z 4 + 3 + 1 = 8 a d e z 2 + 3 + 1 = 6 (the shortest path)

The Traveling Salesman Problem Consider the following problem: A traveling salesman wants to visit each of n cities exactly once and return to his starting point. For example, suppose that the salesman wants to visit Detroit, Toledo, Saginaw, Grand Rapids, and Kalamazoo (see Figure 5). In which order should he visit these cities to travel the minimum total distance?

Shortest circuit : Total distance

Shortest circuit : Total distance