Lab 10 - Graph Theory Computer Science 1FC3

Similar documents
CHAPTER 2. Graphs. 1. Introduction to Graphs and Graph Isomorphism

Graphs. Pseudograph: multiple edges and loops allowed

Varying Applications (examples)

Introduction III. Graphs. Motivations I. Introduction IV

DEFINITION OF GRAPH GRAPH THEORY GRAPHS ACCORDING TO THEIR VERTICES AND EDGES EXAMPLE GRAPHS ACCORDING TO THEIR VERTICES AND EDGES

Section 10.1: Graphs and Graph Models. Introduction to Graphs Definition of a Graph Types of Graphs Examples of Graphs

Foundations of Discrete Mathematics

Binary Relations McGraw-Hill Education

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. An Introduction to Graph Theory

CPCS Discrete Structures 1

Graphs. Introduction To Graphs: Exercises. Definitions:

CS 441 Discrete Mathematics for CS Lecture 24. Relations IV. CS 441 Discrete mathematics for CS. Equivalence relation

Basics of Graph Theory

Studies on Dimultigraph and Prograph Based Applications of Graph Theory in Computer Science

An Introduction to Graph Theory

Module 11. Directed Graphs. Contents

Lecture 20 : Trees DRAFT

Math 443/543 Graph Theory Notes

2. CONNECTIVITY Connectivity

A graph is finite if its vertex set and edge set are finite. We call a graph with just one vertex trivial and all other graphs nontrivial.

9.5 Equivalence Relations

Ramsey s Theorem on Graphs

Graph Theory S 1 I 2 I 1 S 2 I 1 I 2

Math 443/543 Graph Theory Notes

March 20/2003 Jayakanth Srinivasan,

CMSC 380. Graph Terminology and Representation

Lecture 10. Graphs Vertices, edges, paths, cycles Sparse and dense graphs Representations: adjacency matrices and adjacency lists Implementation notes

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

Math 170- Graph Theory Notes

Chapter 3. Set Theory. 3.1 What is a Set?

GRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS

Introduction aux Systèmes Collaboratifs Multi-Agents

Logic: The Big Picture. Axiomatizing Arithmetic. Tautologies and Valid Arguments. Graphs and Trees

Introduction to Graph Theory

An Introduction to Graph Theory

Graph Overview (1A) Young Won Lim 5/9/18

Minimum spanning trees

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao,David Tse Note 8

Chapter 2 Graphs. 2.1 Definition of Graphs

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS

11.4 Bipartite Multigraphs

14.1 Encoding for different models of computation

Discrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs

Kuratowski Notes , Fall 2005, Prof. Peter Shor Revised Fall 2007

Introduction to Graphs

Graphs. Carlos Moreno uwaterloo.ca EIT

CS200: Graphs. Prichard Ch. 14 Rosen Ch. 10. CS200 - Graphs 1

(5.2) 151 Math Exercises. Graph Terminology and Special Types of Graphs. Malek Zein AL-Abidin

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur

Ma/CS 6a Class 8: Eulerian Cycles

University of Toronto Department of Mathematics

Lecture 3: Recap. Administrivia. Graph theory: Historical Motivation. COMP9020 Lecture 4 Session 2, 2017 Graphs and Trees

Algorithm Analysis Advanced Data Structure. Chung-Ang University, Jaesung Lee

v V Question: How many edges are there in a graph with 10 vertices each of degree 6?

Algorithms: Lecture 10. Chalmers University of Technology

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7

c) the set of students at your school who either are sophomores or are taking discrete mathematics

Introduction to Graphs

An Investigation of the Planarity Condition of Grötzsch s Theorem

Graph theory was invented by a mathematician named Euler in the 18th century. We will see some of the problems which motivated its study.

Elements of Graph Theory

Notebook Assignments

Dieter Jungnickel (2008), Graphs, Networks and Algorithms, 3rd edition, which is available online via SpringerLink.

Number Theory and Graph Theory

Stanford University CS359G: Graph Partitioning and Expanders Handout 18 Luca Trevisan March 3, 2011

Graphs Definitions. Gunnar Gotshalks. GraphDefinitions 1

Lattice Tutorial Version 1.0

Discrete Wiskunde II. Lecture 6: Planar Graphs

Graph Theory. Part of Texas Counties.

Graphs. The ultimate data structure. graphs 1

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

Graph Theory. ICT Theory Excerpt from various sources by Robert Pergl

Finding Strongly Connected Components

Section 8.2 Graph Terminology. Undirected Graphs. Definition: Two vertices u, v in V are adjacent or neighbors if there is an edge e between u and v.

DISCRETE MATHEMATICS

Inf 496/596 Topics in Informatics: Analysis of Social Network Data

Brief History. Graph Theory. What is a graph? Types of graphs Directed graph: a graph that has edges with specific directions

Chapter 5 Graph Algorithms Algorithm Theory WS 2012/13 Fabian Kuhn

1.2 Venn Diagrams and Partitions

Chapter 8 Topics in Graph Theory

2.2 Set Operations. Introduction DEFINITION 1. EXAMPLE 1 The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is, EXAMPLE 2

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G.

Graph Adjacency Matrix Automata Joshua Abbott, Phyllis Z. Chinn, Tyler Evans, Allen J. Stewart Humboldt State University, Arcata, California

Math.3336: Discrete Mathematics. Chapter 10 Graph Theory

This Lecture. We will first introduce some basic set theory before we do counting. Basic Definitions. Operations on Sets.

Math 443/543 Graph Theory Notes 11: Graph minors and Kuratowski s Theorem

Ordinary Differential Equation (ODE)

Graphs. The ultimate data structure. graphs 1

Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) Web search views web pages as a graph

CS 311 Discrete Math for Computer Science Dr. William C. Bulko. Graphs

Graph Theory. 1 Introduction to Graphs. Martin Stynes Department of Mathematics, UCC January 26, 2011

Week 7: Introduction to Graph Theory. 24 and 26 October, 2018

13 th Annual Johns Hopkins Math Tournament Saturday, February 19, 2011 Automata Theory EUR solutions

INTRODUCTION TO GRAPH THEORY. 1. Definitions

Basic Definitions and Concepts Complement to the Prologue and to Chapter 1, Respecting the Rules

Treewidth and graph minors

Dissertation Title. Royal Holloway logo guidelines. Dissertation Subtitle. Stephen D. Wolthusen

ON THE STRUCTURE OF SELF-COMPLEMENTARY GRAPHS ROBERT MOLINA DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE ALMA COLLEGE ABSTRACT

Lecture 1: Introduction and Motivation Markus Kr otzsch Knowledge-Based Systems

Transcription:

Lab 10 - Graph Theory Computer Science 1FC3 Author: Dai Tri Man Lê ledt@mcmaster.ca Abstract. Graphs, graphs application in Computer Science and how to work with graphs in Maple. 1 Why Graphs? Graphs are extremely important in Computer Science. There are several main reasons for that: Graphs can be used to represent many problems in computer science that are otherwise abstract. Finding a way to represent the solution to a problem as a graph can present new approaches to solving the problem or even lead directly to a solution derived from graph theory. Many problems computers are used to solve involve representing relationships between objects, places, or concepts. Because graphs can be either directed or undirected, they are a flexible method of showing connections. For instance, you can describe who knows whom in a room as a collection of vetices, each representing a person, and directed edges, each representing that one person knows another. We shall now discuss different kinds of graphs and their applications in Computer Science. 2 Undirected Graphs 2.1 Simple Graph Definition. A simple graph G = (V, E) consists of V, a nonempty finite set of vertices and E, a set of unordered pairs of distinct elements of V called edges. (End of Definition.) Simple graphs are often used to represent network models (models with links between elements) where the only information is the location of the connections. For example, the following diagram is a graph of a real world local area network (LAN). 2.2 Multigraph and Pseudograph Sometimes we want to model the situation when there more than one connection between some pairs of vertices, which is not allowed in simple graph. Hence, we need the concept of multigraph: 1

Definition. A multigraph G = (V, E) consists of V, a nonempty finite set of vertices and E, a finite multiset set of unordered pairs of distinct elements of V called edges. Thus, multiple edges between two vertices are allowed in a multigraph.(end of Definition.) Remark. a multiset (sometimes also called a bag) differs from a set in that each member has a multiplicity, which is a natural number indicating (loosely speaking) how many times it is a member, or perhaps how many memberships it has in the multiset. For example, in the multiset {a, a, b, b, b, c}, the multiplicities of the members a, b, and c are respectively 2, 3, and 1.(End of Remark.) An example of a (nice!) multigraph is shown below: Note that neither simple graphs nor multigraphs may have loops. All such graphs can only have edges between distinct pairs of vertices. In order to allow loops, we have need the notion of a pseudograph (multigraph with loops). A formal definition of pseudo graph is given below: Definition. A pseudograph G = (V, E) consists of V, a nonempty finite set of vertices and E, a finite multiset set of unordered pairs of elements of V called edges. Thus, multiple edges between two vertices and loops are allowed in a pseudo.(end of Definition.) An example of a pseudo is shown below: Remark. Graphs which are simple graphs, multigraphs and pseudographs are all called undirected graph, which means the direction of the edges does not matter. This is why each edge the previous definitions is precisely defined to be an unordered pair of vertices. As we can see, as far as undirected graphs go, pseudographs are the most general type of graphs since they may contains loops and multiple edges. (End of Remark.) 2.3 Exercise 1: 1. Classify the following graphs: 2. Why in the definition of simple graph, when talking about the set of edges, we say a set of unordered pairs without mentioning the word finite as in the definition of multigraph and pseudograph? Is this a mistake? 2

2.4 Maple Constructing and Visualizing Graphs Maple has a large collection of commands related to graph theory, all found in the networks package. In order to access these commands we use the following command to include the network package: with(networks); Once we have loaded the package in this manner, we can use the newly defined Maple commands to create new graphs and then add or delete edges and vertices. To create a new graph called G1, we use the new command. This command to creates a new graph object and initializes all the underlying structures of the graph. The command only accepts one argument the name of the new graph. G1 := new(): This newly created graph does not yet have any vertices or edges. These must be added to the graph using such commands as addvertex, addedge. We continue to construct an example of a simple graph by adding vertices to represent cities and edges to represent the communications links of a computer network between the chosen cities. We use the addvertex command to add vertices and the addedge command to add edges and build up the graph. For our example we have chosen a set of 4 places T (Toronto), H (Hamilton), K (Kitchener), L (London). The following command adds this set of seven vertices to the newly created graph G1. addvertex( T,H,K,L,G1); The newly created vertex names are listed in response to the command. To complete our graph representing a nation-wide computer network we next add the edges representing the connections between the various cities. Each connection is undirected. Information may flow in either direction. Undirected connections are defined by using a set of two vertices the two cities joined by the connection. To add such edges to our graph we use the addedge command in a similar manner to the use of the addvertex command. This time the first argument to the procedure call is the set of vertex pairs representing the new edges. The last argument is the name of the graph to which the edges are to be added. addedge([{t,h},{h,k},{k,l},{l,t},{h,l}],g1); As each edge is created, a name is generated. The edge names are displayed as the value of this operation. The names are used so that, if necessary, more than one connection can occur between cities. To discover the vertex pair associated with a particular edge in G1, use the ends command, as in ends(e1,g1); To find the set of all pairs corresponding to edges of a particular graph use the command ends(g1); To find the set of all edges in G1 use the command edges(g1); To find the set of all vertices in G1 use the command vertices(g1); To draw G1 use the command draw(g1); You should get a picture like this: 3

To delete edge(s) from a graph use the command delete({e1},g1): To delete a vertex or vetices from a Graph use the command Adjacency Matrices delete({t},g1): Graphs can also be represented in the form of matrices which are called adjacency matrices. The major advantage of matrix representation is that the calculation of paths and cycles can easily be performed using well known operations of matrices. However, the disadvantage is that this form of representation takes away from the visual aspect of graphs. It would be difficult to illustrate in a matrix, properties that are easily illustrated graphically. In Maple, we can find the adjacency matrix of a graph using command adjacency. For example, the following command will construct the adjacency matrix of G1 is our example: adjacency(g1); You should get a matrix like this: 0 1 1 1 1 0 1 0 1 1 0 1 1 0 1 0 This is a symmetric matrix! Do you know why? 2.5 Exercise 2: 1. Use the command addvertex, addedges to recover the original G1 graph. After that try to use this command: addedge([{t,h},{h,k},{k,l}],g1): adjacency(g1); Is this adjacency matrix different from the one from the original G1? Why or why not? 2. Use the following command to learn more about Maple s networks package:?networks 4

3 Directed Graph and Directed Multigraph 3.1 Directed Graph Directed graphs are used when the direction of the connections is important. For example, if traffic in a computer network only flowed in particular directions, we might use a directed graph to model it. A formal definition of directed graph more formally below: Definition. A directed graph G = (V, E) consists of V, a nonempty finite set of vertices and E, a set of unordered pairs of elements of V called edges. (End of Definition.) Remark. Question: How is this definition different from the definition of simple graph? (End of Remark.) One interesting application (not mentioned in Rosen) of directed graph is to specify the hierarchical import relationships between modules. This kind of directed graph is called module dependency graph. Here is an example of a module dependency graph: Here is another small and colorful one: 5

3.2 Directed Multigraph Sometimes we also want to allow multiples edges between two vertices in directed graphs, so we need the notion of directed multigraph: Definition. A directed multigraph G = (V, E) consists of V, a nonempty finite set of vertices and E, a finite multiset set of ordered pairs of distinct elements of V called edges. Thus, multiple edges between two vertices are allowed in a multigraph.(end of Definition.) An example application of directed multigraph in Computer Science is to graphically represent finite automata (finite state machine). Here is an example of an automaton: This kind of diagram is called state transition diagram or simply state diagram. 3.3 Maple The Maple commands for directed graph are exactly the same for undirected graph, except we represent edges as ordered pairs of two vertices rather than as sets of two vertices. For example, if we add one more alteration to our computer network, where we are limited to only unidirectional lines of transmission, we would need to create a directed graph in order to represent this new computer network. This can be easily accomplished by signifying an edge as an ordered list of 2 vertices instead of an (unordered) set of 2 vertices. As an example, consider the graph G2 which has the same vertex set as graph G1, but has only unidirectional information lines between cities. We would represent such a computer network as the following directed graph in Maple: G2 := new(): addvertex( T,H,K,L,G2); addedge([[t,h],[h,k],[k,l],[l,t],[h,l]],g2); draw(g2); adjacency(g2); Notice the difference between adjacency matrices of G2 and G1. 3.4 Exercise 3: 1. Write a Maple program that takes input as a natural number n and constructs an n-complete graph K n. Recall a complete graph is a simple graph with an edge between every pair of vertices. 2. Write a Maple program that takes input as a natural number n and constructs a complete n-partite graphs K m1,m 2,...,m n. That is, graphs where the vertex set is partitioned into m disjoint sets with m i, i = 1, 2... n vertices, respectively, and with every vertex in one of subsets of the partition connected to every vertex of the graph not in this subset by an edge. 6