CS1022 Computer Programming & Principles Lecture 7.1 Graphs (1)

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

CSE 211 Discrete Mathematics
CS1022 Computer Programming & Principles
Graphs, representation, isomorphism, connectivity
CS1022 Computer Programming & Principles Lecture 8.1 Digraphs (1)
CS1022 Computer Programming & Principles
Discrete Mathematics Dr.-Ing. Erwin Sitompul
Discrete Mathematics 6. GRAPHS Lecture 10 Dr.-Ing. Erwin Sitompul
CS203 Lecture 15.
© 2008 Pearson Addison-Wesley. All rights reserved Chapter 13 Mathematics and Business.
Epp, section 10.? CS 202 Aaron Bloomfield
CS 253: Algorithms Chapter 22 Graphs Credit: Dr. George Bebis.
Analysis of Algorithms CS 477/677
Chapter 8 Topics in Graph Theory
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.
Introduction to Graphs
13 May 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Introduction.
Section 14.1 Intro to Graph Theory. Beginnings of Graph Theory Euler’s Konigsberg Bridge Problem (18 th c.)  Can one walk through town and cross all.
Euler Circuits and Paths
Koenigsberg bridge problem It is the Pregel River divided Koenigsberg into four distinct sections. Seven bridges connected the four portions of Koenigsberg.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Section 2.1 Euler Cycles Vocabulary CYCLE – a sequence of consecutively linked edges (x 1,x2),(x2,x3),…,(x n-1,x n ) whose starting vertex is the ending.
Introduction to Graphs
Representing Graphs Wade Trappe. Lecture Overview Introduction Some Terminology –Paths Adjacency Matrix.
Graphs. Graph A “graph” is a collection of “nodes” that are connected to each other Graph Theory: This novel way of solving problems was invented by a.
Chapter 11 Graphs and Trees This handout: Terminology of Graphs Eulerian Cycles.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
Graphs and Euler cycles Let Maths take you Further…
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Copyright © Cengage Learning. All rights reserved.
GRAPH Learning Outcomes Students should be able to:
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley.
1 Excursions in Modern Mathematics Sixth Edition Peter Tannenbaum.
Can you connect the dots as shown without taking your pen off the page or drawing the same line twice.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 9 (Part 2): Graphs  Graph Terminology (9.2)
Based on slides by Y. Peng University of Maryland
Week 11 - Monday.  What did we talk about last time?  Binomial theorem and Pascal's triangle  Conditional probability  Bayes’ theorem.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Basic Notions on Graphs. The House-and-Utilities Problem.
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.
Graphs Edge(arc) Vertices can be even or odd or undirected (two-way) Edges can be directed (one-way) This graph is connected. Degree(order) = 3 Odd vertex.
Discrete Mathematical Structures: Theory and Applications
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Lecture 10: Graph-Path-Circuit
Introduction to Graphs. This Lecture In this part we will study some basic graph theory. Graph is a useful concept to model many problems in computer.
Graph theory and networks. Basic definitions  A graph consists of points called vertices (or nodes) and lines called edges (or arcs). Each edge joins.
MAT 2720 Discrete Mathematics Section 8.2 Paths and Cycles
Lecture 52 Section 11.2 Wed, Apr 26, 2006
Excursions in Modern Mathematics, 7e: Copyright © 2010 Pearson Education, Inc. 5 The Mathematics of Getting Around 5.1Euler Circuit Problems 5.2What.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Graphs Rosen, Chapter 8. NOT ONE OF THESE! One of these!
(CSC 102) Lecture 30 Discrete Structures. Graphs.
Grade 11 AP Mathematics Graph Theory Definition: A graph, G, is a set of vertices v(G) = {v 1, v 2, v 3, …, v n } and edges e(G) = {v i v j where 1 ≤ i,
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
Leda Demos By: Kelley Louie Credits: definitions from Algorithms Lectures and Discrete Mathematics with Algorithms by Albertson and Hutchinson graphics.
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
Graph Theory An Introduction.
Data Structures Graphs - Terminology
Chapter 5 Fundamental Concept
Graph theory Definitions Trees, cycles, directed graphs.
Discrete Maths 9. Graphs Objective
Can you draw this picture without lifting up your pen/pencil?
Graphs Chapter 13.
Excursions in Modern Mathematics Sixth Edition
Representing Graphs Wade Trappe.
Graph Theory Relations, graphs
Chapter 10 Graphs and Trees
Presentation transcript:

CS1022 Computer Programming & Principles Lecture 7.1 Graphs (1)

Plan of lecture What we mean by “graphs” How it started Terminology & result Simple graphs Adjacency matrix Subgraphs Paths and cycles Acyclic and connected graphs Connectivity algorithm 2 CS1022

What we mean by “graphs” Graphs: very specific & special mathematical model – Not “graph” as in a plot of a function using x-y axes Is the term familiar? – We’ve used them to represent relations – We did not define them formally 3 CS

Origins of graphs (1) Leonhard Euler (18 th Century mathematician) Studied and solved the Königsberg bridge problem – Königsberg is now Kaliningrad (Russia) – It consisted of 2 islands in a river with 7 bridges Problem: 1.Find a route starting and ending at the same place 2.Traversing all bridges exactly once 4 CS1022 Leonhard Euler

Origins of graphs (2) Euler modelled the problem using a graph – Vertices (or nodes) represent parts of the city – Edges (or links) represent bridges He proved that there was no such route 5 CS1022

Graphs and computing Many real-life problems can be modelled as graphs – Networks, web sites, memory management, etc. If the problem is modelled as a graph then we can use existing solutions – Find a path between two nodes in a graph – Find a node which all paths go through – Etc. We can also rely on many important results – Certain graph problems only solved in exponential time – Only small instances can be solved  6 CS1022

Terminology (1) A graph consists on – A set of vertices (nodes) – A set of edges (links) The Königsberg problem – Vertices A, B, C, D (places) – Edges a, b, c, d, e, f, g (bridges) – Start/end on a vertex using each edge exactly once Eulerian graph: – Has a route beginning and ending on a vertex – The route uses all edges exactly once Eulerian trail: – Is the route itself – Vertices may be repeated (but not the edges) 7 CS1022 A B C D a b c d e f g

Euler’s result (1) Euler noticed that if a graph is Eulerian then – Each time an edge is used to travel to some vertex – A different edge would be required to leave that vertex This applies no matter how many times a particular vertex needed to be visited Hence, if an Eulerian trail exists, then there must be an even number of edges meeting at each vertex Euler also proved the converse: – If there is an even number of edges meeting at each vertex then there is an Eulerian trail 8 CS1022

Euler’s result (2) So the result is – A graph in which every pair of vertices is joined by some route is Eulerian if, and only if, all the vertices have even degree The degree of a vertex, denoted as  (v), is the number of edges incident to v. There is no such route in the Königsberg graph –  (B)   (C)   (B)  3,  (A)  5 – There are vertices (all of them!) of odd degree 9 CS1022

Euler’s result (3) Is there a lesson to learn here? – We thought we needed to compute routes, etc. but the problem can be solved by checking graph properties We can now write a program which 1.Takes as input a graph 2.Checks the property It’s a simpler problem than computing all paths/routes, starting from all nodes and back 3.Outputs Yes, it is an Eulerian graph No, it is not an Eulerian graph 10 CS1022

Simple graphs (1) A simple graph G is the pair (V, E) where – V is a finite set of vertices and – E is a finite set of edges Such that G contains – No loops (no vertex is joined to itself by an edge) – No multiple edges (at most 1 edge joining two vertices) Königsberg graph is not simple: – Two edges connecting A and B – (Other multiple edges too) 11 CS1022

Simple graphs (2) In simple graphs, vertices u and v are adjacent if they are connected by an edge e – Edge e is incident to u and v Thus the set of edges E can be regarded as a set of pairs of adjacent vertices – E is an irreflexive, symmetric relation on V – Irreflexive: there are no loops in simple graphs – Symmetric: an edge from u to v, also connects v to u Edges are not directed – these are not digraphs! uv (or vu) represents unique edge from u to v 12 CS1022

Adjacency matrix The logical matrix M of the edge relation is called adjacency matrix Irreflexive and symmetric properties mean that – Adjacency matrix is symmetric about leading diagonal – Leading diagonal is all Fs 13 CS1022 v1v1 v2v2 v3v3 v4v4 v1v1 FTFT v2v2 TFTT v3v3 FTFF v4v4 TTFF

Example Suppose G  (V, E) V   a, b, c, d, e  E   ab, ae, bc, bd, ce, de  Draw simple graphShow adjacency matrix 14 CS1022 abcde aF bF cF dF eF a b e c d abcde aFT bTF cF dF eF abcde aFTT bTF cF dF eTF abcde aFTT bTFT cTF dF eTF abcde aFTT bTFTT cTF dTF eTF abcde aFTT bTFTT cTFT dTF eTTF abcde aFTT bTFTT cTFT dTFT eTTTF abcde aFTFFT bTFTTF cFTFFT dFTFFT eTFTTF abcde aFTFFT bTFTTF cFTFFT dFTFFT eTFTTF

Subgraph A subgraph of G  (V, E) is any graph G  (V, E) such that V  V and E  E – That is, a subgraph has a subset of vertices and edges – N.B.: if removing vertices, then edges may need to go 15 CS1022

Paths A path of length k in a graph is a sequence of distinct vertices v 0, v 1, , v k such that v i–1 v i is an edge, 1  i  k We denote this path as v 0 v 1  v k Example: – a b c e d is a path – b a e c is a path – d e c b a is a path – b e a is not a path – c e a b c is not a path 16 CS1022 a b e c d

Cycles A cycle in a graph is a sequence of vertices v 0, v 1, , v k such that – v i–1 v i is an edge, 1  i  k (that is, it is a path) – v 0  v k (first and last vertices are the same) – v i–1 v i, v i–1  v i, 2  i  k (other vertices are all distinct) Example: – a b c e a is a cycle – b a e c b is a cycle – d e c b d is a cycle 17 CS1022 a b e c d

Acyclic and connected graphs A graph for which we cannot find cycles is called an acyclic graph A graph is connected if there is a path between every pair of vertices Example of graph acyclic and connected: 18 CS1022 a b e c d

Connectivity number Any graph can be partitioned into subgraphs, each of which is connected Minimal number of connected subgraphs is called the connectivity number, c(G) – Connectivity issues are important in the study of computer networks 19 CS1022

Connectivity algorithm (1) The algorithm below computes the value c(G) 20 CS1022 input graph G consisting of pair (V, E) begin V:= V; c := 0; while V   do begin Choose y  V; Find all vertices joined to y by some path; Remove these vertices and y from V and the corresponding edges from E; c := c  1; end output c end

Connectivity algorithm (2) Trace algorithm with input 21 CS1022 input graph G consisting of pair (V, E) begin V:= V; c := 0; while V   do begin Choose y  V; Find all vertices joined to y by some path; Remove these vertices and y from V and the corresponding edges from E; c := c  1; end output c end V c Initial values  1, 2, 3, 4, 5, 6, 7, 8  0 V c Initial values  1, 2, 3, 4, 5, 6, 7, 8  0 Choose y = 1 V c Initial values  1, 2, 3, 4, 5, 6, 7, 8  0 Choose y = 1 V c Initial values  1, 2, 3, 4, 5, 6, 7, 8  0 Choose y = 1  2, 4, 5, 7  1 V c Initial values  1, 2, 3, 4, 5, 6, 7, 8  0 Choose y = 1  2, 4, 5, 7  1 Choose y = 2 V c Initial values  1, 2, 3, 4, 5, 6, 7, 8  0 Choose y = 1  2, 4, 5, 7  1 Choose y = 2 V c Initial values  1, 2, 3, 4, 5, 6, 7, 8  0 Choose y = 1  2, 4, 5, 7  1 Choose y = 2{7}2 V c Initial values  1, 2, 3, 4, 5, 6, 7, 8  0 Choose y = 1  2, 4, 5, 7  1 Choose y = 2{7}2 Choose y = 7  3

Connectivity algorithm (3) Therefore c(G)  3 The 3 connected components are: N.B.: algorithm does not compute these! 22 CS

Further reading R. Haggarty. “Discrete Mathematics for Computing”. Pearson Education Ltd (Chapter 7) Wikipedia’s entry on graph theory Wikibooks entry on graph theory 23 CS1022