Graphs and Their Representations

Slides:



Advertisements
Similar presentations
CS203 Lecture 15.
Advertisements

Based on slides by Y. Peng University of Maryland
Analysis of Algorithms CS 477/677
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.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
1 Slides based on those of Kenneth H. Rosen Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Graphs.
Introduction This chapter explores graphs and their applications in computer science This chapter explores graphs and their applications in computer science.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
1 Representing Graphs. 2 Adjacency Matrix Suppose we have a graph G with n nodes. The adjacency matrix is the n x n matrix A=[a ij ] with: a ij = 1 if.
Applied Discrete Mathematics Week 12: Trees
Applied Combinatorics, 4th Ed. Alan Tucker
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Introduction to Graphs
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Graphs Rosen 8.1, 8.2. There Are Many Uses for Graphs! Networks Data organizations Scene graphs Geometric simplification Program structure and processes.
GRAPH Learning Outcomes Students should be able to:
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
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,
Copyright © Cengage Learning. All rights reserved. CHAPTER 10 GRAPHS AND TREES.
Representing and Using Graphs
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 9 (Part 2): Graphs  Graph Terminology (9.2)
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Chapter 6 Graph Theory R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001.
1 CS104 : Discrete Structures Chapter V Graph Theory.
Based on slides by Y. Peng University of Maryland
(CSC 102) Lecture 28 Discrete Structures. Graphs.
GRAPHS THEROY. 2 –Graphs Graph basics and definitions Vertices/nodes, edges, adjacency, incidence Degree, in-degree, out-degree Subgraphs, unions, isomorphism.
Week 11 - Monday.  What did we talk about last time?  Binomial theorem and Pascal's triangle  Conditional probability  Bayes’ theorem.
Data Structures & Algorithms Graphs
Basic Notions on Graphs. The House-and-Utilities Problem.
Planar Graphs Graph Coloring
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
1 12/2/2015 MATH 224 – Discrete Mathematics Formally a graph is just a collection of unordered or ordered pairs, where for example, if {a,b} G if a, b.
COSC 2007 Data Structures II Chapter 14 Graphs I.
An Introduction to Graph Theory
Discrete Mathematical Structures: Theory and Applications
Graph Theory and Applications
Introduction to Graph Theory
Graph theory and networks. Basic definitions  A graph consists of points called vertices (or nodes) and lines called edges (or arcs). Each edge joins.
Chapter 9: Graphs.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
Great Theoretical Ideas in Computer Science for Some.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Graph Theory Graph Theory - History Leonhard Euler's paper on “Seven Bridges of Königsberg”, published in 1736.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Paths and circuits.
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.
Chapter Chapter Summary Graphs and Graph Models Graph Terminology and Special Types of Graphs Representing Graphs and Graph Isomorphism Connectivity.
Special Graphs By: Sandeep Tuli Astt. Prof. CSE.
Graph theory Definitions Trees, cycles, directed graphs.
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.
Mathematical Structures for Computer Science Chapter 6
Based on slides by Y. Peng University of Maryland
Chapter 10.7 Planar Graphs These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 7th ed., by Kenneth H.
Graphs Chapter 13.
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.
CS100: Discrete structures
Chapter 10.7 Planar Graphs These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 7th ed., by Kenneth H.
Chapter 10.7 Planar Graphs These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 7th ed., by Kenneth H.
Chapter 10.7 Planar Graphs These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 8th ed., by Kenneth H.
Introduction to Graph Theory
Applied Discrete Mathematics Week 13: Graphs
Chapter 10.7 Planar Graphs These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 7th ed., by Kenneth H.
Agenda Review Lecture Content: Shortest Path Algorithm
Chapter 10.7 Planar Graphs These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 7th ed., by Kenneth H.
Presentation transcript:

Mathematical Structures for Computer Science Chapter 5 Graphs and Trees Mathematical Structures for Computer Science Chapter 5 Copyright © 2006 W.H. Freeman & Co. MSCS Slides Graphs and Trees

Graphs and Their Representations Definitions of a Graph DEFINITION (INFORMAL): GRAPH A graph is a nonempty set of nodes (vertices) and a set of arcs (edges) such that each arc connects two nodes. Our graphs will always have a finite number of nodes and arcs. Example: The set of nodes in the airline map below is {Chicago, Nashville, Miami, Dallas, St. Louis, Albuquerque, Phoenix, Denver, San Francisco, Los Angeles}. There are 16 arcs; Phoenix–Albuquerque, ChicagoNashville, MiamiDallas, and so on. Section 5.1 Graphs and Their Representations

Formal Definition of a Graph The informal definition of a graph works quite well if we have the visual representation of the graph before us to show which arcs connect which nodes. But without the picture, we need a concise way to convey this information. DEFINITION (FORMAL): GRAPH A graph is an ordered triple (N, A, g) where: N = a nonempty set of nodes (vertices) A = a set of arcs (edges) g = a function associating with each arc a an unordered pair x–y of nodes called the endpoints of a Section 5.1 Graphs and Their Representations

Formal Definition of a Graph: Example Sketch a graph having nodes {1, 2, 3, 4, 5}, arcs {a1, a2, a3, a4, a5, a6}, and function g(a1) = 1–2, g(a2) = 1–3, g(a3) = 3–4, g(a4) = 3–4, g(a5) = 4–5, and g(a6) = 5–5. Section 5.1 Graphs and Their Representations

Graphs and Their Representations Directed Graphs Directed graph: the arcs of a graph begin at one node and end at another. DEFINITION: DIRECTED GRAPH A directed graph (digraph) is an ordered triple (N, A, g) where: N = a nonempty set of nodes A = a set of arcs g = a function associating with each arc a an ordered pair (x, y) of nodes where x is the initial point and y is the terminal point of a A directed graph, therefore, has a direction associated with each arc. Section 5.1 Graphs and Their Representations

Directed Graphs: Example In the example below there are four nodes and five arcs. The function g associating arcs with endpoints performs the mapping g(a1) = (1, 2), meaning that arc a1 begins at node 1 and ends at node 2. Also, g(a3) = (1, 3), but g(a4) = (3, 1). Section 5.1 Graphs and Their Representations

Graphs and Their Representations Other Forms of Graphs Besides imposing direction on the arcs of a graph, we may want to modify the basic definition of a graph in other ways. Labeled graph:A graph whose nodes carry identifying information, such as the names of the cities in the map of airline routes. Weighted graph: A graph where each arc has some numerical value, or weight, associated with it. For example, a graph that indicates the distances of the various routes in the airline map. The term “graph” is used to mean an undirected graph. To refer to a directed graph, one always says “directed graph.” Section 5.1 Graphs and Their Representations

Applications of Graphs Although the idea of a graph is very simple, an amazing number of situations have relationships between items that lend themselves to graphical representation. Graphical representations of partially ordered sets: (Hasse diagrams) were introduced in Chapter 4. A PERT chart (e.g., Figure 4.7) is a directed graph. The E-R diagram (e.g., Figure 4.10) is a graph. The commutative diagram illustrating composition of functions (see Figure 4.23) is a directed graph. Chapter 7 will introduce logic networks and represent them as directed graphs. Directed graphs will also be used to describe finite-state machines in Chapter 8. As seen earlier, the airline route map was a graph. Any representation of transportation routes is a graph (road maps, computer networks, water pipelines, etc.). Section 5.1 Graphs and Their Representations

Graphs and Their Representations Graph Terminology Two nodes in a graph are adjacent if they are the endpoints associated with an arc. 1 and 3 are adjacent nodes, but 1 and 4 are not. A loop in a graph is an arc with endpoints n–n for some node n; arc a3 is a loop with endpoints 2–2. A graph with no loops is loop-free. Two arcs with the same endpoints are parallel arcs; arcs a1 and a2 are parallel. A simple graph is one with no loops or parallel arcs. An isolated node is adjacent to no other node; 5 is an isolated node. The degree of a node is the number of arc ends at that node. Nodes 1 and 3 have degree 3, node 2 has degree 5, node 4 has degree 1, and node 5 has degree 0. Section 5.1 Graphs and Their Representations

Graphs and Their Representations Graph Terminology Because the function g that relates arcs to endpoints in the formal definition of a graph is indeed a function, each arc has a unique pair of endpoints. If g is a one-to-one function, then there is at most one arc associated with a pair of endpoints; such graphs have no parallel arcs. A complete graph is one in which any two distinct nodes are adjacent. A subgraph of a graph consists of a set of nodes and a set of arcs that are subsets of the original node set and arc set, respectively, in which the endpoints of an arc must be the same nodes as in the original graph. Below is a complete subgraph of the graph from the previous slide. Section 5.1 Graphs and Their Representations

Graphs and Their Representations Graph Terminology A path from node n0 to node nk is a sequence n0, a0, n1, a1, ... , nk  1, ak  1, nk of nodes and arcs where, for each i, the endpoints of arc ai are ni–ni + 1. If such a path exists, then nk is reachable n0. In Figure seen here, one path from node 2 to node 4 consists of the sequence 2, al, 1, a2, 2, a4, 3, a6, 4. The length of a path is the number of arcs it contains; if an arc is used more than once, it is counted each time it is used. The length of the path described above from node 2 to node 4 is 4. A graph is connected if there is a path from any node to any other node. A cycle in a graph is a path from some node n0 back to n0, where no arc appears more than once in the path sequence, n0 is the only node appearing more than once, and n0 occurs only at the ends. A graph with no cycles is acyclic. Section 5.1 Graphs and Their Representations

Bipartite Complete Graphs DEFINITION: BIPARTITE COMPLETE GRAPH A graph is a bipartite complete graph if its nodes can be partitioned into two disjoint nonempty sets N1 and N2 such that two nodes x and y are adjacent if and only if x  N1 and y  N2. If N1 = m and N2 = n, such a graph is denoted by Km,n. The figure below is not a complete graph because it is not true that every node is adjacent to every other node. However, the nodes can be divided into two disjoint sets, {1, 2} and {3, 4, 5}, such that any two nodes chosen from the same set are not adjacent but any two nodes chosen one from each set are adjacent. Section 5.1 Graphs and Their Representations

Graphs and Their Representations Isomorphic Graphs Two graphs may appear quite different in their visual representation but still be the same graph according to our formal definition. The graphs in the figures below are the same—they have the same nodes, the same arcs, and the same arc-to-endpoint function. Structures that are the same except for relabeling are called isomorphic structures. Section 5.1 Graphs and Their Representations

Graphs and Their Representations Isomorphic Graphs DEFINITION: ISOMORPHIC GRAPHS Two graphs (N1, A1, g1,) and (N2, A2, g2) are isomorphic if there are bijections f1: N1 → N2 and f2: A1 → A2 such that for each arc a ε A1, g1(a) = x–y if and only if g2[ f2(a)] = f1(x)–f1(y). The bijections for the isomorphic graphs below are: Section 5.1 Graphs and Their Representations

Isomorphism in Simple Graphs Graph isomorphism is easier to establish if we restrict our attention to simple graphs. If one can find an appropriate function f1 mapping nodes to nodes, then a function f2 mapping arcs to arcs is trivial because there is at most one arc between any pair of endpoints. THEOREM ON SIMPLE GRAPH ISOMORPHISM Two simple graphs (N1, A1, g1) and (N2, A2, g2) are isomorphic if there is a bijection f: N1 → N2 such that for any nodes ni and nj of N1, ni and nj are adjacent if and only if f (ni) and f (nj) are adjacent. (The function f is called an isomorphism from graph 1 to graph 2.) Section 5.1 Graphs and Their Representations

Proving That Graphs Are Not Isomorphic To prove that two graphs are not isomorphic, we must prove that the necessary bijection(s) do(es) not exist. Certain conditions under which it is clear that two graphs are not isomorphic are: One graph has more nodes than the other. One graph has more arcs than the other. One graph has parallel arcs and the other does not. One graph has a loop and the other does not. One graph has a node of degree k and the other does not. One graph is connected and the other is not. One graph has a cycle and the other does not. Section 5.1 Graphs and Their Representations

Graphs and Their Representations Planar Graphs A planar graph is one that can be represented (on a sheet of paper, that is, in the plane) so that its arcs intersect only at nodes. Designers of integrated circuits want all components in one layer of a chip to form a planar graph so that no connections cross. A simple, connected, planar graph (when drawn in its planar representation, with no arcs crossing) divides the plane into a number of regions, including totally enclosed regions and one infinite exterior region. Leonhard Euler observed a relationship between the number n of nodes, the number a of arcs, and the number r of regions in such a graph. This relationship is known as Euler’s formula: n  a + r = 2. Section 5.1 Graphs and Their Representations

Graphs and Their Representations Planar Graphs THEOREM ON THE NUMBER OF NODES AND ARCS For a simple, connected, planar graph with n nodes and a arcs: If the planar representation divides the plane into r regions, then n  a + r = 2. If n ≥ 3, then a ≤ 3n  6. If n ≥ 3 and there are no cycles of length 3, then a ≤ 2n – 4. We can use this theorem to prove that certain graphs are not planar. Section 5.1 Graphs and Their Representations

Graphs and Their Representations Homeomorphic Graphs DEFINITION: HOMEOMORPHIC GRAPHS Two graphs are homeomorphic if both can be obtained from the same graph by a sequence of elementary subdivisions in which a single arc x–y is replaced by two new arcs xv–vy connecting to a new node v. The graphs in parts (b) and (c) of the figure below are homeomorphic because each can be obtained from part (a) by a sequence of elementary subdivisions. (However, neither can be obtained from the other by a sequence of elementary subdivisions.) Section 5.1 Graphs and Their Representations

Graphs and Their Representations Nonplanar Graphs A graph that is planar cannot be turned into a nonplanar graph by elementary subdivisions. A graph that is nonplanar cannot be turned into a planar graph by elementary subdivisions. Homeomorphic graphs are either both planar or both nonplanar. KURATOWSKI THEOREM A graph is nonplanar if and only if it contains a subgraph that is homeomorphic to K5 or K3,3. If a graph has a subgraph homeomorphic to the nonplanar graphs K5 or K3,3, then the subgraph—and hence the entire graph—is nonplanar. Section 5.1 Graphs and Their Representations

Graphs and Their Representations Adjacency Matrices The usual computer representations of a graph involve one of two data structures, either an adjacency matrix or an adjacency list. Suppose a graph has n nodes numbered n1, n2, ... , nn. This numbering imposes an arbitrary ordering on the set of nodes; recall that a set is an unordered collection. Having ordered the nodes, we can form an n x n matrix where entry i,j is the number of arcs between nodes ni and nj. This matrix is called the adjacency matrix A of the graph with respect to this ordering. Thus, aij = p where there are p arcs between ni and nj. For example, the following graph has a corresponding adjacency matrix. Section 5.1 Graphs and Their Representations

Graphs and Their Representations Adjacency Lists Many graphs, far from being complete graphs, have relatively few arcs. Such graphs have sparse adjacency matrices; that is, the adjacency matrices contain many zeros. Yet if the graph has n nodes, it still requires n2 data items to represent the adjacency matrix, even if many of these items are zero. Any algorithm or procedure in which every arc in the graph must be examined requires looking at all n2 items in the matrix. A graph with relatively few arcs can be represented more efficiently by storing only the nonzero entries of the adjacency matrix. An adjacency list consists of a list for each node of all the nodes adjacent to it. Pointers are used to get us from one item in the list to the next. Such an arrangement is called a linked list. There is an array of n pointers, one for each node, to get each list started. Section 5.1 Graphs and Their Representations

Adjacency Lists: Example The adjacency list for the graph of the figure on the left contains a four-element array of pointers, one for each node. The pointer for each node points to an adjacent node, which points to another adjacent node, and so forth. In the figure, the dot indicates a null pointer, meaning that there is nothing more to be pointed to or that the end of the list has been reached. Section 5.1 Graphs and Their Representations