© Jalal Kawash 2010 Graphs Peeking into Computer Science.

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Introduction to Graphs
1 Lecture 5 (part 2) Graphs II Euler and Hamiltonian Path / Circuit Reading: Epp Chp 11.2, 11.3.
Lecture 21 Paths and Circuits CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
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.
BY: MIKE BASHAM, Math in Scheduling. The Bridges of Konigsberg.
Euler Circuits and Paths
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.
Discrete Structures Chapter 7B Graphs Nurul Amelina Nasharuddin Multimedia Department.
James Tam Graphs You will learn basic principles of graphs as well as how they can be applied to problem solving.
Representing Graphs Wade Trappe. Lecture Overview Introduction Some Terminology –Paths Adjacency Matrix.
Homework collection Thursday 3/29 Read Pages 160 – 174 Page 185: 1, 3, 6, 7, 8, 9, 12 a-f, 15 – 20.
MATH 310, FALL 2003 (Combinatorial Problem Solving) Lecture 5,Wednesday, September 10.
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.
Euler and Hamilton Paths
Chapter 11 Graphs and Trees This handout: Terminology of Graphs Eulerian Cycles.
Graphs and Euler cycles Let Maths take you Further…
Euler Paths and Circuits. The original problem A resident of Konigsberg wrote to Leonard Euler saying that a popular pastime for couples was to try.
Discrete Math Round, Round, Get Around… I Get Around Mathematics of Getting Around.
The Bridge Obsession Problem By Vamshi Krishna Vedam.
GRAPH Learning Outcomes Students should be able to:
Graph Theory Chapter 6 from Johnsonbaugh Article(6.1, 6.2)
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 9 (Part 1): Graphs  Introduction to Graphs (9.1)
1 Excursions in Modern Mathematics Sixth Edition Peter Tannenbaum.
Graph Theory Topics to be covered:
Euler and Hamilton Paths
Can you connect the dots as shown without taking your pen off the page or drawing the same line twice.
It's a world-wide webby wonderland.. Graphs are often used to represent real-world information and real-world structures. Graph Theory was even invented.
CS 200 Algorithms and Data Structures
© Jalal Kawash 2010 Graphs Peeking into Computer Science.
© Jalal Kawash 2010 Graphs Peeking into Computer Science.
Week 11 - Monday.  What did we talk about last time?  Binomial theorem and Pascal's triangle  Conditional probability  Bayes’ theorem.
5.4 Graph Models (part I – simple graphs). Graph is the tool for describing real-life situation. The process of using mathematical concept to solve real-life.
Aim: What is an Euler Path and Circuit?
Topics Paths and Circuits (11.2) A B C D E F G.
Discrete Mathematical Structures: Theory and Applications
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.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 9 (Part 1): Graphs  Introduction to Graphs (9.1)
Associated Matrices of Vertex Edge Graphs Euler Paths and Circuits Block Days April 30, May 1 and May
Euler Paths and Circuits. The original problem A resident of Konigsberg wrote to Leonard Euler saying that a popular pastime for couples was to try.
MAT 2720 Discrete Mathematics Section 8.2 Paths and Cycles
Lecture 52 Section 11.2 Wed, Apr 26, 2006
Aim: Graph Theory – Paths & Circuits Course: Math Literacy Do Now: Aim: What are Circuits and Paths? Can you draw this figure without retracing any of.
M Clements Formal Network Theory. Introduction Practical problem – The Seven Bridges of Königsberg Network graphs Nodes & edges Degrees Rules/ axioms.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Euler and Hamiltonian Graphs
Copyright 2013, 2010, 2007, Pearson, Education, Inc. Section 14.1 Graphs, Paths, and Circuits.
Graphs Rosen, Chapter 8. NOT ONE OF THESE! One of these!
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
1 Lecture 5 (part 2) Graphs II (a) Circuits; (b) Representation Reading: Epp Chp 11.2, 11.3
Week 10 - Wednesday.  What did we talk about last time?  Counting practice  Pigeonhole principle.
© Jalal Kawash 2010 Graphs And Algorithms Peeking into Computer Science.
Excursions in Modern Mathematics Sixth Edition
Excursions in Modern Mathematics Sixth Edition
Euler and Hamiltonian Graphs
Data Structures Graphs - Terminology
Euler Paths and Circuits
Graphs Rosen, Chapter 8.
Konigsberg’s Seven Bridges
Discrete Maths 9. Graphs Objective
Can you draw this picture without lifting up your pen/pencil?
Euler Circuits and Paths
Excursions in Modern Mathematics Sixth Edition
Euler Circuits and Paths
Section 14.1 Graphs, Paths, and Circuits
Graph Theory Relations, graphs
Graphs, Paths, and Circuits
Presentation transcript:

© Jalal Kawash 2010 Graphs Peeking into Computer Science

© Jalal Kawash 2010Peeking into Computer Science Reading Assignment Mandatory: Chapter 3 – Sections 3.1 & 3.2 2

Graphs Abstraction of Data 3

© Jalal Kawash 2010Peeking into Computer Science Objectives At the end of this section, you will be able to: 1. Define directed and undirected graphs 2. Use graphs to model data 3. Use graph terminology 4. Represent graphs using adjacency matrices 4

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: What Is A Graph Used For? To show relationships (people, objects, locations etc.) 5 Jane JimAnne JoeMarkMikeMary

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: What Is A Graph Used For? Visualizing connections e.g., “6 degrees of separation” 6 A B

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Practical Applications (Graphs) They can be used anytime that the relationships between some entities must be visualized. Examples: ◦A few from will be used in the following slides:  7

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra Example: JT’s Vacation 1 8 Hotel :Ammanl Jerusalem Jerash Mount Nebo Wadi Rum $100/8 hours $75/6 hours $400/12 hours $225/10 hours

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Other Examples 1 Logistics: ◦Making sure that you deliver your items to every street within a part of the city. You want to cover every street but at the same time minimize travel time. ◦Telecommuincations: Find the cheapest way to connect communication stations (TV, telephone, computer network) so that a station is connected to any other (directly, or through intermediate stations)

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Other Examples 1 (2) (More logistics) ◦A warehouse should be placed in a city (a region) so that the sum of shortest distances to all other points (regions) is minimal. This is useful for lowering the cost of transporting goods from a warehouse to clients

© Jalal Kawash 2010Peeking into Computer Science Graphs 11 Havana Calgary Frankfurt Cairo

© Jalal Kawash 2010Peeking into Computer Science Definition A graph G is defined as: G = (V,E) where V(G) is a set of vertices E(G) is a set of edges (pairs of vertices) JT’s note: Vertices are ‘things’ being connected, edges are the connectors. Directed Graph: edges are one-way Undirected Graph: edges are two-way Labeled Graphs: edges have weights 12 Vertex Edge

© Jalal Kawash 2010Peeking into Computer Science An undirected graph V = {A, B, C, D} E = {{A,B},{A,C},{A,D},{B,C}} 13 A BC D

© Jalal Kawash 2010Peeking into Computer Science A directed graph V = {A, B, C, D, E, F} 14 A BC D E F E = { (A,B), (B,A), (B,C), (A,D), (C,A), (D,E), (C,F), (E,A), (E,E), (F,E)}.

© Jalal Kawash 2010Peeking into Computer Science A labeled undirected graph 15 A BC E D

© Jalal Kawash 2010Peeking into Computer Science Graph Terminology Adjacent vertices: connected by an edge A and B are adjacent D and C are not 16 A BC D

© Jalal Kawash 2010Peeking into Computer Science Graph Terminology There is a Path from A to C ◦One path: A to B to C Cycle = a path starting and ending with the same vertex 17 A BC D

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Path Example There is a path between vertices if they are directly connected by an edge or indirectly connected. ◦Red Deer and Lethbridge are not adjacent but there is at least one path from Red Deer to Lethbridge. 18 Edmonton Red Deer Calgary Banff Canmore Medicine Hat Lethbridge

© Jalal Kawash 2010Peeking into Computer Science Graph Terminology Degree of a vertex = Number of edges touching it degree of C = 2 degree of A = 3 19 A BC D

© Jalal Kawash 2010Peeking into Computer Science Graph Terminology A is adjacent to B B is adjacent from A There is a Path from A to C There is no path that starts at D In-degree of A is 1 Out-degree of A is 2 20 A BC D

© Jalal Kawash 2010Peeking into Computer Science The Web as a Directed Graph 21

© Jalal Kawash 2010Peeking into Computer Science The WWW Is A Graph The World Wide Web itself can be visualized as a directed graph. ◦Vertex = web page, Edge = link between pages. 22

© Jalal Kawash 2010Peeking into Computer Science The WWW Is A Graph (2) 23

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Applying Graphs To Web Design Visualizing the layout of a page as a graph can be useful in web design. ◦Are there sufficient connections between pages? ◦Do the connections (links) make sense to visitor? ◦Although it should be possible to reach any page without too much clicking (rule of thumb is 3), there are some pages that should always be accessible e.g., home page, contact page etc. 24

© Jalal Kawash 2010Peeking into Computer Science Graph Representation 25 Debra Ali John AliciaSarah Mike

© Jalal Kawash 2010Peeking into Computer Science Graph Representation 26 AB C D E ABCDE A01000 B10110 C01001 D01001 E00110

© Jalal Kawash 2010Peeking into Computer Science Multigraphs In a multigraph the set of edges is a multiset Edges can be repeated Graphs are special cases of multigraphs 27 AB C D E Parallel edges

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Application Multigraphs Example: path finding when alternatives are possible. 28 A B

Euler Paths 29

© Jalal Kawash 2010Peeking into Computer Science Objectives At the end of this section, you will be able to: 1. Understand how graphs are used to represent data 2. Appreciate the ability of graphs to lead to generalized conclusions 3. Define Euler tours and paths 4. Identify under which conditions an Euler circuit or path exists in a graph 5. Understand why such conditions are required 6. Learn the Euler circuit algorithm 30

© Jalal Kawash 2010Peeking into Computer Science Konigsberg Today called Kaliningrad in the Russian Republic In 1736 was in Prussia The town had seven bridges on the Pregel River 31

© Jalal Kawash 2010Peeking into Computer Science Konigsberg Layout 32 Island Land River

© Jalal Kawash 2010Peeking into Computer Science Seven Bridges 33 A D C B

© Jalal Kawash 2010Peeking into Computer Science Konigsberg’s Walk People in 1736 wondered if it is possible to take the following walk in town: Start at some location in town Travel across all bridges without crossing any bridge twice End the walk where it started They wrote to Swiss Mathematician Leonhard Euler for help 34

© Jalal Kawash 2010Peeking into Computer Science Leonhard Euler 1707 –1783 The greatest mathematician of the 18th century and one of the greatest of all time a pioneering Swiss mathematician and physicist important discoveries in graph theory introduced much of the modern mathematical terminology and notation 35

© Jalal Kawash 2010Peeking into Computer Science Konigsberg Multigraph 36 A D C B

© Jalal Kawash 2010Peeking into Computer Science Konigsberg multigraph 37

© Jalal Kawash 2010Peeking into Computer Science Konigsberg multigraph 38

© Jalal Kawash 2010Peeking into Computer Science Konigsberg multigraph 39

© Jalal Kawash 2010Peeking into Computer Science Euler’s Response Is there a path through this graph that ◦Starts at a vertex ◦Ends in the same vertex ◦Passes through every edge once ◦Does not cross an edge more than once? Called an Euler Circuit Such a walk is impossible on any graph as long as the graph has one vertex with an odd degree 40

© Jalal Kawash 2010Peeking into Computer Science Euler’s Response There is at least one vertex of an odd degree Does not work (the start vertex must have an even degree) 41

© Jalal Kawash 2010Peeking into Computer Science Even-Degree Vertex To cross every bridge once Each vertex must have an even degree 42 vertex Coming in using this bridge Must leave using a different bridge

© Jalal Kawash 2010Peeking into Computer Science Odd-Degree Vertex Must come in using some bridge Must leave using a different bridge We’re stuck 43 vertex Coming in using this bridge Leaving using this bridge This bridge cannot be used Except to come in

© Jalal Kawash 2010Peeking into Computer Science The Starting/Ending Vertex Must leave using some bridge Either we come back to leave again (need two new bridges) Or we come back to stay (using another bridge) Cannot be of an odd degree: we need another bridge to come back 44 Start/ end vertex Leaving using this bridge Come back to leave Leave Come back to end tour

© Jalal Kawash 2010Peeking into Computer Science An Easier Problem Is there a path through this graph that ◦Starts at some vertex ◦Ends at a (possibly different) vertex ◦Passes through every edge once ◦Does not cross an edge more than once? Called a Euler Path Note that if there is a circuit, then there is a path If not, then the path is necessarily not a circuit 45

© Jalal Kawash 2010Peeking into Computer Science Euler Path – Start Vertex The starting vertex must have an odd degree Never come back to stay 46 Start vertex Leaving using this bridge Come back to leave Leave

© Jalal Kawash 2010Peeking into Computer Science Euler Path – End Vertex The end vertex must have an odd degree 47 end vertex Come back to leave Leave end tour

© Jalal Kawash 2010Peeking into Computer Science Other Vertices All other vertices must have an even degree Every in must have a matching out on “new” bridges 48 other vertex in out

© Jalal Kawash 2010Peeking into Computer Science Euler (non-cycle) Path Requirements Start and end vertices must have odd degrees Every other vertex must have an even degree There is no Euler Path for the Konigsberg graph 49

© Jalal Kawash 2010Peeking into Computer Science No Euler Path for this Graph 50

© Jalal Kawash 2010Peeking into Computer Science A Similar Problem Can you draw this shape with the rules: ◦Draw continuously, cannot lift pen from one position to another ◦Draw each line once, cannot let pen run on top of an already drawn line 51

© Jalal Kawash 2010Peeking into Computer Science Graph Representation 52 A BC ED

© Jalal Kawash 2010Peeking into Computer Science Graph Representation Is there a Euler Circuit ◦No (some vertices have odd degrees) Is there a Euler Path ◦Yes (exactly two vertices have odd degrees) Path must start at an odd-degree vertex and ends at another odd-degree one 53 A BC ED

© Jalal Kawash 2010Peeking into Computer Science Euler Circuit Algorithm Given a graph G (all vertices have even degrees) : 1. Construct a circuit c, starting and ending at arbitrary vertex in G 2. Remove all the edges of c from G 3. Repeat until G has no edges: a)Construct a circuit c’ in G that starts (ends) in a vertex v that is in c b)Add c’ to c at v c)Remove all the edges of c’ from G 54

© Jalal Kawash 2009Peeking into Computer Science A B C DE F I J

© Jalal Kawash 2010Peeking into Computer Science 1. Construct a circuit c, starting and ending at arbitrary vertex in G 56 A B C DE F I J Note: other choices for c are possible c: A, B, D, C, A

© Jalal Kawash 2010Peeking into Computer Science 2. Remove all the edges of c from G 57 A B C DE F I J c: A, B, D, C, A

© Jalal Kawash 2010Peeking into Computer Science 3. Repeat until G has no edges: 58 A B C DE F I J c: A, B, D, C, A

© Jalal Kawash 2010Peeking into Computer Science a)Construct a circuit c’ in G that starts (ends) in a vertex v that is in c 59 A B C DE F I J c: A, B, D, C, A c’: A, J, I, A

© Jalal Kawash 2010Peeking into Computer Science a)Construct a circuit c’ in G that starts (ends) in a vertex v that is in c 60 A B C DE F I J c: A, B, D, C, A c’: A, J, I, A

© Jalal Kawash 2010Peeking into Computer Science a)Add c’ to c at v b)Remove all the edges of c’ from G 61 A B C DE F I J c: A, B, D, C, A c’: A, J, I, A c: A, J, I, A, B, D, C, A

© Jalal Kawash 2010Peeking into Computer Science a)Add c’ to c at v b)Remove all the edges of c’ from G 62 A B C DE F I J c: A, J, I, A, B, D, C, A

© Jalal Kawash 2010Peeking into Computer Science Repeat a), b), and c) 63 A B C DE F I J c: A, J, I, A, B, D, C, A c’: D, F, E, D c: A, J, I, A, B, D, C, A An Euler circuit c: A, J, I, A, B, D, F, E, D, C, A

© Jalal Kawash 2010Peeking into Computer Science The graph has no more edges, stop 64 A B C DE F I J An Euler circuit c: A, J, I, A, B, D, F, E, D, C, A