Data Structures Chapter 12 Graphs Andreas Savva. 2 Definition A graph consists of a set of vertices together with a set of edges. If e = (v,w) is an edge.

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

Discrete Mathematics University of Jazeera College of Information Technology & Design Khulood Ghazal Connectivity Lecture _13.
Analysis of Algorithms CS 477/677
22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Algorithms and Data Structures
TECH Computer Science Graphs and Graph Traversals  // From Tree to Graph  // Many programs can be cast as problems on graph Definitions and Representations.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 8, Part I Graph Algorithms.
Graphs Chapter 30 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Introduction This chapter explores graphs and their applications in computer science This chapter explores graphs and their applications in computer science.
Graph Search Methods Spring 2007 CSE, POSTECH. Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. A search method.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Graphs Chapter 30 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Introduction to Graphs
Introduction to Graphs What is a Graph? Some Example applications of Graphs. Graph Terminologies. Representation of Graphs. –Adjacency Matrix. –Adjacency.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Applications of Depth-First Search
1 Section 8.4 Connectivity. 2 Paths In an undirected graph, a path of length n from u to v, where n is a positive integer, is a sequence of edges e 1,
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Graphs Chapter 28 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Lecture 13 Graphs. Introduction to Graphs Examples of Graphs – Airline Route Map What is the fastest way to get from Pittsburgh to St Louis? What is the.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
Based on slides by Y. Peng University of Maryland
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.
Computer Science: A Structured Programming Approach Using C Graphs A graph is a collection of nodes, called vertices, and a collection of segments,
COSC 2007 Data Structures II Chapter 14 Graphs I.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
 Quotient graph  Definition 13: Suppose G(V,E) is a graph and R is a equivalence relation on the set V. We construct the quotient graph G R in the follow.
Graphs Upon completion you will be able to:
Chapter 9: Graphs.
Graphs Chapter 28 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
CSC 252: Algorithms October 28, 2000 Homework #5: Graphs Victoria Manfredi (252a-ad) notes: -Definitions for each of the graph concepts are those presented.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Leda Demos By: Kelley Louie Credits: definitions from Algorithms Lectures and Discrete Mathematics with Algorithms by Albertson and Hutchinson graphics.
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
CMSC 341 Graphs. 2 Basic Graph Definitions A graph G = (V,E) consists of a finite set of vertices, V, and a set of edges, E. Each edge is a pair (v,w)
Introduction to Graphs
Graphs.
Introduction to Graphs
Graph Algorithms Using Depth First Search
Refresh and Get Ready for More
Graphs Chapter 11 Objectives Upon completion you will be able to:
Graphs.
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Paths and Connectivity
Paths and Connectivity
GRAPHS.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Introduction to Graphs
Introduction to Graphs
Presentation transcript:

Data Structures Chapter 12 Graphs Andreas Savva

2 Definition A graph consists of a set of vertices together with a set of edges. If e = (v,w) is an edge with vertices v and w, then v and w lie on e and they are said to be adjacent vertices. A graph consists of a set of vertices together with a set of edges. If e = (v,w) is an edge with vertices v and w, then v and w lie on e and they are said to be adjacent vertices. Undirected graph (just graph) Directed graph (digraph) Graphs C CC C CC H H H H H H Benzene molecule London Athens Larnaka Paris Vienna Berlin Rome Madrid Lisbon Olympic Airways air routes A B C D E F Message transmission in a network

3 Undirected Graphs A path is a sequence of distinct vertices, each adjacent to the next. A path is a sequence of distinct vertices, each adjacent to the next. A graph is called connected if there is a path from any vertex to any other vertex. A graph is called connected if there is a path from any vertex to any other vertex. A cycle is a path containing at least three vertices such that the last vertex on the path is adjacent to the first. A cycle is a path containing at least three vertices such that the last vertex on the path is adjacent to the first. If a graph is disconnected, then the maximal subset of connected vertices is called a component. If a graph is disconnected, then the maximal subset of connected vertices is called a component. A graph with no cycles is a tree. A graph with no cycles is a tree.

4 Undirected Graphs ConnectedPathCycle Disconnected 2 components Tree

5 Directed Graphs A directed path is a sequence of distinct vertices, each adjacent to the next always moving in the direction indicated by the arrows. A directed path is a sequence of distinct vertices, each adjacent to the next always moving in the direction indicated by the arrows. A directed cycle is a directed path containing at least three vertices such that the last vertex on the path is adjacent to the first. A directed cycle is a directed path containing at least three vertices such that the last vertex on the path is adjacent to the first. A directed graph is called strongly connected if there is a directed path from any vertex to any other vertex. A directed graph is called strongly connected if there is a directed path from any vertex to any other vertex. If we ignore the direction of the edges and the resulting undirected graph is connected, we call the directed graph weakly connected. If we ignore the direction of the edges and the resulting undirected graph is connected, we call the directed graph weakly connected.

6 Directed Graphs Directed cycle Strongly connected Weakly connected

7 Graph Traversal In many problems, we wish to investigate all the vertices in a graph in some systematic order, just as with binary trees, where we developed several systematic traversal methods. In many problems, we wish to investigate all the vertices in a graph in some systematic order, just as with binary trees, where we developed several systematic traversal methods. Depth-first traversal of a graph Breath-First traversal

8 Depth-first Traversal Depth-first traversal of a graph is analogous to preorder traversal of an ordered tree. Depth-first traversal of a graph is analogous to preorder traversal of an ordered tree. Algorithm: Algorithm: Suppose that the traversal has just visited a vertex v and let w 1, w 2, …, w k be the vertices adjacent to v. Then it next visits w 1 and keep w 2, …, w k waiting. After visiting w 1 we traverse all the vertices to which it is adjacent before returning to traverse w 2, …, w k. Suppose that the traversal has just visited a vertex v and let w 1, w 2, …, w k be the vertices adjacent to v. Then it next visits w 1 and keep w 2, …, w k waiting. After visiting w 1 we traverse all the vertices to which it is adjacent before returning to traverse w 2, …, w k. Strongly connected Start

9 Breadth-first Traversal Breadth-first traversal of a graph is analogous to level-by-level traversal of an ordered tree. Breadth-first traversal of a graph is analogous to level-by-level traversal of an ordered tree. Algorithm: Algorithm: Suppose that the traversal has just visited a vertex v and let w 1, w 2, …, w k be the vertices adjacent to v. Then it next visits all the vertices adjacent to v, putting the vertices adjacent to these in a waiting list to be traversed after all vertices adjacent to v have been visited. Suppose that the traversal has just visited a vertex v and let w 1, w 2, …, w k be the vertices adjacent to v. Then it next visits all the vertices adjacent to v, putting the vertices adjacent to these in a waiting list to be traversed after all vertices adjacent to v have been visited. Strongly connected Start

10 Traversal of a Tree Depth-first traversal Breadth-first traversal