Graphs Chapter 8 from Drozdek. Definitions A graph is a generalization of a tree. A simple graph consists of a nonempty set of vertices and possibly an.

Slides:



Advertisements
Similar presentations
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Advertisements

Review Binary Search Trees Operations on Binary Search Tree
Data Structures Using C++
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
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.
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.
Data Structures Using C++
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
Data Structures Using Java1 Chapter 11 Graphs. Data Structures Using Java2 Chapter Objectives Learn about graphs Become familiar with the basic terminology.
 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.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
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.
Graphs. Graphs Many interesting situations can be modeled by a graph. Many interesting situations can be modeled by a graph. Ex. Mass transportation system,
CS 206 Introduction to Computer Science II 11 / 05 / 2008 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.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Graphs. One limitation of the trees is that the trees are hierarchal in nature. They only represent relations of hierarchal types such as relations between.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Data Structures Using C++ 2E
Been-Chian Chien, Wei-Pang Yang, and Wen-Yang Lin 6-1 Chapter 6 Graphs Introduction to Data Structure CHAPTER 6 GRAPHS 6.1 The Graph Abstract Data Type.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Chapter 2 Graph Algorithms.
Chapter 14 Graphs. © 2004 Pearson Addison-Wesley. All rights reserved Terminology G = {V, E} A graph G consists of two sets –A set V of vertices,
ICS220 – Data Structures and Algorithms Dr. Ken Cosh Week 8.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
Data Structures and Algorithms Ver. 1.0 Session 17 Objectives In this session, you will learn to: Implement a graph Apply graphs to solve programming problems.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
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.
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.
COSC 2007 Data Structures II
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Graphs Upon completion you will be able to:
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.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Unit 11 Graphs (2) King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department.
Data Structures & Algorithm Analysis lec(8):Graph T. Souad alonazi
A vertex u is reachable from vertex v iff there is a path from v to u.
Csc 2720 Instructor: Zhuojun Duan
Faculty of Computers and Information
Introduction to Graphs
Common final examinations
Graphs Chapter 13.
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Chapter 11 Graphs.
Graphs Part 2 Adjacency Matrix
All pairs shortest path problem
Discrete Mathematics Lecture 13_14: Graph Theory and Tree
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Chapter 16 1 – Graphs Graph Categories Strong Components
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

Graphs Chapter 8 from Drozdek

Definitions A graph is a generalization of a tree. A simple graph consists of a nonempty set of vertices and possibly an empty set of edges Each edge being a set of two vertices. A directed graph, or digraph, where the edges are directed from one vertice to another.

More definitions A path from v 1 to v n is a sequence of edges from v 1 to v n. If none of the edges are repeated and v 1 = v n then this is a circuit. A weighted graph if each edge has an assigned number. A graph with n vertices is complete and is denoted K n if for each pair of distinct vertices there is exactly one edge connecting them.

Representations Adjacency list Specifies all the vertices that are adjacent to each vertex in the graph. Adjacency matrix Is a binary matrix such that each entry of the matrix is A ij = 1 if there exists an edge(v i,v j ) A ij = 0 otherwise Incidence matrix Is a binary matrix such that each entry of the matrix is A ij = 1 if edge e j is incident with vertex v i A ij = 0 otherwise

Traversals Depth first search Each vertex v is visited and then each unvisited vertex adjacent to v is visited. If a vertex has no adjacent vertices or all of its adjacent vertices have been visited, we backtrack to the predecessor of v. The traversal ends when the initial vertices is returned to.

Depth First Search DFS(v) Num(v) = i++; For all vertices u adjacent to v If num(u) is 0 Attach edge(uv) to edges DFS(u) depthFirstSearch() For all vertices v Num(v) = 0; Edges = null; i=1 While there is a vertex v such that num(v) is 0 DFS(v) Output edges

Breadth First Search breadthFirstSearch() For all vertices u Num(u) = 0 Edges = null i=1 While there is a vertex v such that num(v) == 0 Num(v)=i++ Enqueue(v) While queue is not empty V = dequeue() For all vertices u adjacent to v If num(u) is 0 Num(u) = i++ Enqueue(u) Attach edge(vu) to edges Output edges

Shortest Path Classic problem in graph theory. A path between two vertices on a weighted graph is needed. What is the shortest path to get there?

Label Setting and Label Correcting There are two main categories for shortest path problems. Label setting For each pass, one vertex is set to a constant value until the end of execution. This limits to positive values. Label correcting Allows for the value of any vertex to be changed at any time.

genericShortestPathAlgorithm(weightedSimple digraph, vertex first) for all vertices v currDist(v) = ∞ currDist(first) = 0 initialize toBeChecked while toBeChecked is not empty v = a vertex from toBeChecked remove v from toBeChecked for all vertices u adjacent to v if currDist(u) > currDist(v) + weight(edge(vu)) currDist(u) = currDist(v) + weight(edge(vu)) predecessor(u) = v add u toBeChecked if it is not there Generic Shortest Path

Differences How is v = a vertex in toBeChecked chosen? Dijkstra chose a vertex with the smallest current distance. To obtain Dijkstra’s algorithm we change the selection of v to: v = a vertex in toBeChecked with mimimal currDist(v)

Example

Label Correcting What happens if a label has a negative weight? The label setting methods fail. So the label correcting methods solve this issue.

Ford’s Algorithm FordAlgorthim(weight simple diagraph, vertex first) for all vertices v currDist(v) = ∞ while there is an edge(vu) such that currDist(u) > currDist(v) + weight(edge(vu)) currDist(u) = currDist(v) + weight(edge(vu))

Example