Graphs Chapter 12.

Slides:



Advertisements
Similar presentations
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Advertisements

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)
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
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.
CSC 213 – Large Scale Programming Lecture 27: Graph ADT.
CSC 213 ORD DFW SFO LAX Lecture 20: Graphs.
© 2004 Goodrich, Tamassia Graphs1 ORD DFW SFO LAX
Introduction to Graphs
1 Graphs ORD DFW SFO LAX Many slides taken from Goodrich, Tamassia 2004.
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.
1 Graphs: Concepts, Representation, and Traversal CSC401 – Analysis of Algorithms Lecture Notes 13 Graphs: Concepts, Representation, and Traversal Objectives:
Graphs1 Part-H1 Graphs ORD DFW SFO LAX
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Graphs1 ORD DFW SFO LAX Graphs2 Outline and Reading Graphs (§6.1) Definition Applications Terminology Properties ADT Data structures.
Graphs1 ORD DFW SFO LAX Graphs2 Outline and Reading Graphs (§6.1) Definition Applications Terminology Properties ADT Data structures.
CSC311: Data Structures 1 Chapter 13: Graphs I Objectives: Graph ADT: Operations Graph Implementation: Data structures Graph Traversals: DFS and BFS Directed.
ECE669 L10: Graph Applications March 2, 2004 ECE 669 Parallel Computer Architecture Lecture 10 Graph Applications.
Graph Operations And Representation. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Lecture17: Graph I Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Graphs – ADTs and Implementations ORD DFW SFO LAX
© 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,
Graphs Part 1. Outline and Reading Graphs (§13.1) – Definition – Applications – Terminology – Properties – ADT Data structures for graphs (§13.2) – Edge.
Graphs. Data Structure for Graphs. Graph Traversals. Directed Graphs. Shortest Paths. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013.
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 CSE 2011 Winter June Graphs A graph is a pair (V, E), where  V is a set of nodes, called vertices  E is a collection of pairs.
Spring 2007Graphs1 ORD DFW SFO LAX
GRAPHS 1. Outline 2  Undirected Graphs and Directed Graphs  Depth-First Search  Breadth-First Search.
1 prepared from lecture material © 2004 Goodrich & Tamassia COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material.
GRAPHS. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different implementations.
COSC 2007 Data Structures II Chapter 14 Graphs I.
CSE 373: Data Structures and Algorithms
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 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,
Graphs Quebec Toronto Montreal Ottawa 449 km 255 km 200 km 545 km Winnipeg 2075 km 2048 km New York 596 km 790 km 709 km.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University Graphs Original Slides by Rada Mihalcea.
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
1 COMP9024: Data Structures and Algorithms Week Eleven: Graphs (I) Hui Wu Session 1, 2016
Graphs ORD SFO LAX DFW Graphs 1 Graphs Graphs
Graphs 10/24/2017 6:47 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Graphs.
Graphs 5/14/ :46 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Graphs 7/18/2018 7:39 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Graphs ORD SFO LAX DFW Graphs Graphs
Graphs ORD SFO LAX DFW Graphs Graphs
Introduction to Graphs
Graphs Part 1.
CMSC 341 Lecture 21 Graphs (Introduction)
Graphs ORD SFO LAX DFW Graphs Graphs
Graphs.
Graphs.
Graphs ORD SFO LAX DFW Graphs Graphs
Graphs CSE 2011 Winter November 2018.
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Graphs ORD SFO LAX DFW Graphs Graphs
Graphs ORD SFO LAX DFW Graphs Graphs
Graphs 4/29/15 01:28:20 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Graphs ORD SFO LAX DFW /15/ :57 AM
Graphs.
Graphs G = (V, E) V are the vertices; E are the edges.
Elementary Graph Algorithms
GRAPHS.
Introduction to Graphs
Presentation transcript:

Graphs Chapter 12

Graphs PVD ORD SFO LGA HNL LAX DFW MIA 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 Example: A vertex represents an airport An edge represents a flight route between two airports and stores the mileage of the route 849 PVD 1843 ORD 142 SFO 802 LGA 1743 337 1387 HNL 2555 1099 LAX 1233 DFW 1120 MIA Chapter 12: Graphs

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 Chapter 12: Graphs

Graphs A graph is a pair (V, E), where V is a set of vertices E is a set of pairs of vertices, called edges Example: V = {A, B, C, D, E} E = {(A,B), (A,D), (C,E), (D, E)} Chapter 12: Graphs

Edge Types flight AA 1206 ORD PVD 849 miles ORD PVD Directed edge ordered pair of vertices (u,v) first vertex u is the origin second vertex v is the destination e.g., a flight Undirected edge unordered pair of vertices (u,v) e.g., a flight route flight AA 1206 ORD PVD 849 miles ORD PVD Chapter 12: Graphs

Directed and Undirected Graphs A graph with directed edges is called a directed graph or digraph Example: flight network A graph with undirected edges is an undirected graph or simply a graph Example: route network Chapter 12: Graphs

Weighted Graphs The edges in a graph may have values associated with them known as their weights A graph with weighted edges is known as a weighted graph Chapter 12: Graphs

Terminology X U V W Z Y a c b e d f g h i j End vertices (or endpoints) of an edge U and V are the endpoints of a Edges incident on a vertex a, d, and b are incident on V Adjacent vertices U and V are adjacent Degree of a vertex X has degree 5 Parallel edges h and i are parallel edges Self-loop j is a self-loop X U V W Z Y a c b e d f g h i j Chapter 12: Graphs

Terminology (cont.) V a b P1 d U X Z P2 h c e W g f Y 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 Examples P1=(V,X,Z) is a simple path P2=(U,W,X,Y,W,V) is a path that is not simple V a b P1 d U X Z P2 h c e W g f Y Chapter 12: Graphs

Terminology (cont.) V a b d U X Z C2 h e C1 c W g f Y A cycle is a simple path in which only the first and final vertices are the same Simple cycle cycle such that all its vertices and edges are distinct Examples C1=(V,X,Y,W,U,V) is a simple cycle C2=(U,W,X,Y,W,V,U) is a cycle that is not simple V a b d U X Z C2 h e C1 c W g f Y Chapter 12: Graphs

Subgraphs A subgraph S of a graph G is a graph such that The vertices of S are a subset of the vertices of G The edges of S are a subset of the edges of G A spanning subgraph of G is a subgraph that contains all the vertices of G Subgraph Spanning subgraph Chapter 12: Graphs

Non connected graph with two connected components Connectivity A graph is connected if there is a path between every pair of vertices A connected component of a graph G is a maximal connected subgraph of G Connected graph Non connected graph with two connected components Chapter 12: Graphs

Trees and Forests A (free) tree is an undirected graph T such that T is connected T has no cycles A forest is an undirected graph without cycles The connected components of a forest are trees Tree Forest Chapter 12: Graphs

Spanning Trees and Forests A spanning tree of a connected graph is a spanning subgraph that is a tree A spanning tree is not unique unless the graph is a tree A spanning forest of a graph is a spanning subgraph that is a forest Graph Spanning tree Chapter 12: Graphs

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 Chapter 12: Graphs

Vertices and edges Represent the vertices by integers from 0 up to |V|-1, where |V| represents the cardinality of V. Define an Edge class containing Source vertex Destination vertex Weight An Edge object represents a directed edge For undirected edges, use two Edge objects, one in each direction Chapter 12: Graphs

Edge Class Chapter 12: Graphs

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 Chapter 12: Graphs

Adjacency List An adjacency list representation of a graph uses an array of lists One list for each vertex Chapter 12: Graphs

Adjacency List 1 2 3 4 5 2 5 1 1 5 4 5 2 4 2 3 5 4 3 4 1 2 An array (Adj) of lists, one list per vertex For each vertex u in V, Adj[u] contains all edges incident on u Space required Θ(n+m), where n denotes the number of vertices, and m denotes the number of edges Chapter 12: Graphs

Adjacency List (continued) Chapter 12: Graphs

Adjacency Matrix Uses a two-dimensional array to represent a graph For an unweighted graph, the entries can be boolean values Or use 1 for the presence of an edge For a weighted graph, the matrix would contain the weights 1 2 3 4 5 1 1 2 3 4 5 1 5 2 4 3 Chapter 12: Graphs

Adjacency Matrix Chapter 12: Graphs

Overview of the Graph Class Hierarchy Chapter 12: Graphs

Class AbstractGraph Chapter 12: Graphs

The ListGraph Class Chapter 12: Graphs

Performance Adjacency List Adjacency Matrix Space n + m n2 n vertices, m edges no parallel edges no self-loops Bounds are “big-Oh” Adjacency List Adjacency Matrix Space n + m n2 Iterate over incident edges of v deg(v) n isEdge (v, w) min(deg(v), deg(w)) 1 insert(v, w, o) Chapter 12: Graphs