Graphs. Introduction Graphs are a collection of vertices and edges Graphs are a collection of vertices and edges The solid circles are the vertices A,

Slides:



Advertisements
Similar presentations
Cpt S 223 – Advanced Data Structures Graph Algorithms: Introduction
Advertisements

22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
22C:19 Discrete Math Graphs Fall 2014 Sukumar Ghosh.
Depth-First Search1 Part-H2 Depth-First Search DB A C E.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
PSU CS Algorithms Analysis and Design Graphs.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Breadth-First Search Seminar – Networking Algorithms CS and EE Dept. Lulea University of Technology 27 Jan Mohammad Reza Akhavan.
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.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 27 Graph Applications.
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.
© 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.
Data Structure and Algorithms (BCS 1223) GRAPH. Introduction of Graph A graph G consists of two things: 1.A set V of elements called nodes(or points or.
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
Graphs Chapter 30 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Graphs CS-240/341. Graphs Used for representing many-to-many relationships –can take two forms directed (digraph) - a finite set of elements called vertices.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Graphs CS-240/341. Uses for Graphs computer networks and routing airline flights geographic maps course prerequisite structures tasks for completing a.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
CS 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
Graphs. Graphs Many interesting situations can be modeled by a graph. Many interesting situations can be modeled by a graph. Ex. Mass transportation system,
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
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.
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
CSC 213 – Large Scale Programming. Today’s Goals  Make Britney sad through my color choices  Revisit issue of graph terminology and usage  Subgraphs,
© 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,
CISC 235: Topic 9 Introduction to Graphs. CISC 235 Topic 92 Outline Graph Definition Terminology Representations Traversals.
Graph Introduction, Searching Graph Theory Basics - Anil Kishore.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
Depth-First Search Lecture 21: Graph Traversals
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.
Graphs Chapter 28 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Graphs and Paths : Chapter 15 Saurav Karmakar
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Chapter 05 Introduction to Graph And Search Algorithms.
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
CSC 213 – Large Scale Programming Lecture 31: Graph Traversals.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 22 Graphs and Applications.
Graphs. Introduction Graphs are a collection of vertices and edges Graphs are a collection of vertices and edges The solid circles are the vertices A,
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
Graphs. What is a graph? In simple words, A graph is a set of vertices and edges which connect them. A node (or vertex) is a discrete position in the.
Refresh and Get Ready for More
Graphs Chapter 13.
Graph Operations And Representation
Graphs G = (V, E) V are the vertices; E are the edges.
Graphs.
Graphs.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Chapter 9 Graph algorithms
Presentation transcript:

Graphs

Introduction Graphs are a collection of vertices and edges Graphs are a collection of vertices and edges The solid circles are the vertices A, B, C and D The solid circles are the vertices A, B, C and D The lines are the edges The lines are the edges

Weighted Graphs We can also assign values to the edges (a cost related to connecting the two vertices together) and form a weighted graph We can also assign values to the edges (a cost related to connecting the two vertices together) and form a weighted graph

Directed Graph There’s also a directed graph (sometimes called a digraph) that makes the edges one- way There’s also a directed graph (sometimes called a digraph) that makes the edges one- way Since edges are only one-way, b has an edge to x, but x does not have an edge to b Since edges are only one-way, b has an edge to x, but x does not have an edge to b As you can probably guess, you can have a weighted, directed graph as well As you can probably guess, you can have a weighted, directed graph as well

Terminology: Connected A graph is said to be connected if there is a path from every vertex to every other vertex in the graph A graph is said to be connected if there is a path from every vertex to every other vertex in the graph If a graph is not connected, then we call it disconnected If a graph is not connected, then we call it disconnected

Terminology: Path A path is a list of vertices in which successive vertices are connected by edges in the graph. In this graph, one example path is A path is a list of vertices in which successive vertices are connected by edges in the graph. In this graph, one example path is A  B  D  A  C A  B  D  A  C A simple path is a path in which no vertex is repeated. A simple path is a path in which no vertex is repeated. Hence, A  B  D  A  C is not a simple path, but A  B  D  C is Hence, A  B  D  A  C is not a simple path, but A  B  D  C is

Terminology: Cycle A cycle is a path that is simple except that the first and last vertices are the same A cycle is a path that is simple except that the first and last vertices are the same In this graph, the path 7  5  6  8  7 is a cycle In this graph, the path 7  5  6  8  7 is a cycle

Terminology: Connected Component A connected component or component is a maximal connected subgraph A connected component or component is a maximal connected subgraph

Graph Representation Adjacency Matrix Adjacency Matrix Adjacency List Adjacency List

Adjacency Matrix An adjacency matrix is simply an N x N matrix (where N is the number of vertices in the graph). An adjacency matrix is simply an N x N matrix (where N is the number of vertices in the graph). Can store boolean (is there an edge?) Can store boolean (is there an edge?) Can store number (how many edges connect nodes) Can store number (how many edges connect nodes) Can store weights (for weighted graph) Can store weights (for weighted graph)

Adjacency List The adjacency list simply keeps a linked list for each vertex that contains the vertices that are neighbors to it (that is, the list of vertices such that there exists an edge from the subject node to each of the vertices) The adjacency list simply keeps a linked list for each vertex that contains the vertices that are neighbors to it (that is, the list of vertices such that there exists an edge from the subject node to each of the vertices) A : B  C  D A : B  C  D B : A  D B : A  D C : A  D C : A  D D : A  B  C D : A  B  C

Motivation Graphs are very useful for representing a large array of problems and for solving everyday “real world” problems, on which the contest loves to focus. Graphs are very useful for representing a large array of problems and for solving everyday “real world” problems, on which the contest loves to focus. Map intersections to vertices and roads to edges, and now you have a representation to help you route fire trucks to fires. Map intersections to vertices and roads to edges, and now you have a representation to help you route fire trucks to fires. Map a network of computers and routers to vertices, physical connections to edges, and you have a way to find the minimum number of hops between two given computers. Map a network of computers and routers to vertices, physical connections to edges, and you have a way to find the minimum number of hops between two given computers. Map a set of rooms that need water to vertices, all combinations of distances between pairs of rooms to the edges, and then you can determine the smallest amount of pipe needed to connect all the rooms together. Map a set of rooms that need water to vertices, all combinations of distances between pairs of rooms to the edges, and then you can determine the smallest amount of pipe needed to connect all the rooms together. Map the buildings on the UCF campus to vertices, the sidewalks between the buildings to vertices, and then you’ll be able to find the shortest walking distance from the Computer Science Building to any other building. Map the buildings on the UCF campus to vertices, the sidewalks between the buildings to vertices, and then you’ll be able to find the shortest walking distance from the Computer Science Building to any other building. Many, many others! Many, many others!

Testing

Depth First Search The name “Depth-First Search” comes from the fact that you search as deep as you can in the graph first The name “Depth-First Search” comes from the fact that you search as deep as you can in the graph first We need an adjacency matrix and an array to keep track of whether we visited a given node yet We need an adjacency matrix and an array to keep track of whether we visited a given node yet adj:array[1..N, 1..N] of Boolean visited:array[1..N] of Boolean (initialized to all false) DFS(node) { visited[node] = true; if (node is target node) then process accordingly for I = 1 to N { if (adj[node][I]) and (not visited[I]) then DFS(I); }

DFS Motivation Most basic searching algorithm Most basic searching algorithm Mazes Mazes Path finding Path finding Cycle detection Cycle detection

DFS Example DB A C ED B A C ED B A C E discovery edge back edge A visited vertex A unexplored vertex unexplored edge

DFS Example DB A C E DB A C E DB A C E D B A C E

Thanks! Thanks for images and other information to: Thanks for images and other information to: Wikipedia Wikipedia Changhui (Charles) Yan Changhui (Charles) Yan