Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs Chapter Chapter Contents Some Examples and Terminology Road Maps Airline Routes Mazes Course Prerequisites Trees Traversals Breadth-First.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Fundamentals of Python: From First Programs Through Data Structures
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.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Graph Searching (Graph Traversal) Algorithm Design and Analysis Week 8 Bibliography: [CLRS] – chap 22.2 –
Data Structures Using C++
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.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
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.
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.
Chapter 9: Graphs Summary Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
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 Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Graphs & Graph Algorithms 2
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
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 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.
Data Structures Using C++ 2E
Computer Science 112 Fundamentals of Programming II Graph Algorithms.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
Graphs Chapter 12.
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,
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Common final examinations When: Wednesday, 12/11, 3:30-5:30 PM Where: Ritter Hall - Walk Auditorium 131 CIS 1166 final When: Wednesday, 12/11, 5:45-7:45.
Elementary Graph Algorithms CLRS Chapter 22. Graph A graph is a structure that consists of a set of vertices and a set of edges between pairs of vertices.
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. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different implementations.
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 Chapter Chapter Contents Some Examples and Terminology Road Maps Airline Routes Mazes Course Prerequisites Trees Traversals Breadth-First.
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.
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 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.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
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.
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.
© 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.
Graphs Chapter 20.
Minimum Spanning Tree Chapter 13.6.
Common final examinations
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
CS202 - Fundamental Structures of Computer Science II
CS120 Graphs.
Comp 245 Data Structures Graphs.
Graphs Chapter 13.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Chapter 11 Graphs.
Chapter 15 Graphs © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
Chapter 16 1 – Graphs Graph Categories Strong Components
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

Spring 2010CS 2251 Graphs Chapter 10

Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph ADT and different implementations of the Graph ADT To learn the breadth-first and depth-first search traversal algorithms To learn some algorithms involving weighted graphs To study some applications of graphs and graph algorithms

Spring 2010CS 2253 More General Trees

Spring 2010CS 2254 Other Linked Information

Spring 2010CS 2255 The internet co/fig/wired.png

Spring 2010CS 2256 Graph Terminology A graph is a data structure that consists of a set of vertices and a set of edges between pairs of vertices Edges represent paths or connections between the vertices The set of vertices and the set of edges must both be finite and neither one be empty A tree is a special case of a graph

Spring 2010CS 2257 Visual Representation of Graphs Vertices are represented as points or labeled circles and edges are represented as lines joining the vertices The physical layout of the vertices and their labeling are not relevant

Spring 2010CS 2258 Directed Graphs The edges of a graph are directed if the existence of an edge from A to B does not necessarily guarantee that there is a path in both directions A graph with directed edges is called a directed graph

Spring 2010CS 2259 Graph Vocabulary A vertex is adjacent to another vertex if there is an edge to it from that other vertex A path is a sequence of vertices in which each successive vertex is adjacent to its predecessor In a simple path, the vertices and edges are distinct except that the first and last vertex may be the same

Spring 2010CS Paths and Cycles A cycle is a simple path in which only the first and final vertices are the same

Spring 2010CS Weighted Graphs The edges in a graph may have values associated with them known as their weights –Weight are usually assumed to be positive A graph with weighted edges is known as a weighted graph

Spring 2010CS Connected vs. Unconnected A graph is connected if there is a path between any pair of vertices in the graph If a graph is not connected, it may still consist of connected endpoints

Spring 2010CS The Graph ADT and Edge Class Java does not provide a Graph ADT In making our own, we need to be able to do the following Create a graph with the specified number of vertices Iterate through all of the vertices in the graph Iterate through the vertices that are adjacent to a specified vertex Determine whether an edge exists between two vertices Determine the weight of an edge between two vertices Insert an edge into the graph

Spring 2010CS The Graph ADT and Edge Class

Spring 2010CS Implementing the Graph ADT Because graph algorithms have been studied and implemented throughout the history of computer science, many of the original publications of graph algorithms and their implementations did not use an object-oriented approach and did not even use abstract data types Two representations of graphs are most common –Edges are represented by an array of lists called adjacency lists, where each list stores the vertices adjacent to a particular vertex –Edges are represented by a two dimensional array, called an adjacency matrix

Spring 2010CS Adjacency List An adjacency list representation of a graph uses an array of lists One list for each vertex

Spring 2010CS Adjacency ListExample 1

Spring 2010CS Adjacency List Example 2

Spring 2010CS Adjacency Matrix Uses a two-dimensional array to represent a graph For an unweighted graph, the entries can be Boolean values For a weighted graph, the matrix would contain the weights

Spring 2010CS Graph Class Hierarchy

Spring 2010CS Class AbstractGraph

Spring 2010CS The ListGraph Class

Spring 2010CS Traversals of Graphs Most graph algorithms involve visiting each vertex in a systematic order Most common traversal algorithms are the breadth first and depth first search

Spring 2010CS Breadth-First Search In a breadth-first search, we visit the start first, then all nodes that are adjacent to it next, then all nodes that can be reached by a path from the start node containing two edges, three edges, and so on –There is no special start vertex in a graph Must visit all nodes for which the shortest path from the start node is length k before we visit any node for which the shortest path from the start node is length k+1

Spring 2010CS Algorithm for Breadth-First Search

Spring 2010CS Example of a Breadth-First Search

Spring 2010CS Trace of Breadth-First Search

Spring 2010CS ??? Breadth-First Search

Spring 2010CS Depth-First Search In depth-first search, you start at a vertex, visit it, and choose one adjacent vertex to visit; then, choose a vertex adjacent to that vertex to visit, and so on until you go no further; then back up and see whether a new vertex can be found

Spring 2010CS Depth-First Search Algorithm

Spring 2010CS Depth-First Search

Spring 2010CS Depth-First Search

Spring 2010CS Implementing Depth-First Search

Spring 2010CS Shortest Path Through a Maze

Spring 2010CS Shortest Path Through a Maze

Spring 2010CS Directed Acyclic Graph Directed graphs with no cycles are called directed acyclic graphs (DAG for short) They come up in a number of kinds of problems –scheduling –trees are DAGs

Spring 2010CS DAG Examples

Spring 2010CS Topological Sort of a Graph A topological sort of a DAG is an ordering of the vertices of the graph such that if (u, v) is an edge, u comes before v in the sort For the graph below –0, 1, 2, 3, 4, 5, 6, 7, 8 is a valid topological sort –0, 3, 1, 4, 6, 2, 5, 7, 8 is a valid topological sort –0, 1, 5, 3, 4, 2, 6, 7, 8 is not a topologicl sort

Spring 2010CS Topological Sort of a Graph If there is an edge (u, v) in a graph, the finish time of u must be after that of v in a depth-first search The the reverse of finish order of a depth- first search is a topological sort Algorithm for topological sort 1.Perform a depth-first search 2.List the vertices in the reverse of their finish order

Spring 2010CS Other Graph Algorithms Shortest Path for weighted graphs –Breadth-first search finds the shortest path if all edges have the same weight Minimum spanning tree –Subset of the edges such that there is exactly one path between any pair of vertices

Spring 2010CS Shortest Path in Weighted Graph Finding the shortest path from a vertex to all other vertices Uses the following data –S is the set of vertices for which shortest distance has been computer –V-S is the remaining vertices –d is an array containing the shortest distance from s to each vertex –p is an array of predecessors for each vertex

Spring 2010CS Shortest Path Algorithm Developed by Edsger Dijkstra

Spring 2010CS Practice

Spring 2010CS Spanning Tree A minimum spanning tree is a subset of the edges of a graph such that there is only one edge between each vertex, and all of the vertices are connected The cost of a spanning tree is the sum of the weights of the edges We want to find the minimum spanning tree or the spanning tree with the smallest cost –Solution formulated by R.C. Prim is very similar to Dijkstra’s algorithm –Kruskal's algorithm is also commonly used

Spring 2010CS Prim’s Algorithm

Spring 2010CS Practice