Graphs Upon completion you will be able to:

Slides:



Advertisements
Similar presentations
Review Binary Search Trees Operations on Binary Search Tree
Advertisements

Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 8, Part I Graph Algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Data Structures ( 数据结构 ) Chapter 10:Graphs. Vocabulary Graph 图 Vertex 顶点 Edge 边 Arc 弧 Directed Graph 有向图 Undirected Graph 无向图 Adjacent Vertices 邻接点 Path.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
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.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
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.
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.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
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.
CS 206 Introduction to Computer Science II 11 / 09 / 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.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Chapter 9 Graph Algorithms Real-life graph problems Algorithms for some graph problems Choice of data structures for graph problems.
© 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,
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,
Graphs. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other The set of.
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
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.
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.
CISC 235: Topic 9 Introduction to Graphs. CISC 235 Topic 92 Outline Graph Definition Terminology Representations Traversals.
Chapter 12 Abstract Data Type. Understand the concept of an abstract data type (ADT). Understand the concept of a linear list as well as its operations.
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++
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.
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.
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.
Lecture #13. Topics 1.The Graph Abstract Data Type. 2.Graph Representations. 3.Elementary Graph Operations.
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.
Data Structures( 数据结构 ) Course 12:Graphs. 2 西南财经大学天府学院 Vocabulary Graph 图 Vertex 顶点 Edge 边 Arc 弧 Directed Graph 有向图 Undirected Graph 无向图 Adjacent Vertices.
Chapter 12 Abstract Data Type.
Unit 10 Graphs (1) King Fahd University of Petroleum & Minerals
Data Structures Graphs - Terminology
Csc 2720 Instructor: Zhuojun Duan
CS120 Graphs.
Comp 245 Data Structures Graphs.
Graphs Chapter 13.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Chapter 11 Graphs.
Graphs.
Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
Graphs G = (V, E) V are the vertices; E are the edges.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
GRAPHS.
Heaps Chapter 6 Section 6.9.
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:

Graphs Upon completion you will be able to: Understand and use basic graph terminology and concepts Define and discuss basic graph and network structures Design and implement graph and network applications Design and implement applications using the graph ADT Define and discuss Dijkstra's shortest path algorithm Data Structures: A Pseudocode Approach with C, Second Edition

11-1 Basic Concepts Directed and Undirected Graphs Cycles and Loops A graph is a collection of nodes, called vertices, and a collection of segments, called lines or edges, connecting pairs of vertices. In Basic Concepts we develop the terminology and structure for graphs. In addition to the graph definitions, discussion points include: Directed and Undirected Graphs Cycles and Loops Connected and Disjoint Graphs Data Structures: A Pseudocode Approach with C, Second Edition

A directed graph or digraph for short, is a graph in which line has a direction (arrow head) to its successor. The lines in a directed graphs are known as arcs. An undirected graph is a graph in which there is no direction on the lines, known as edges. Data Structures: A Pseudocode Approach with C, Second Edition

Two vertices in a graph are said to be adjacent vertices if there exists an edge that directly connects them. A path is a sequence of vertices in which each vertex is adjacent to the next one. It does not make any difference whether or not the graph is directed, it may still have paths. In an undirected graph, you may travel in either directions. Simple path is a path such that all its vertices and edges are distinct. A cycle is a path consisting of at least three vertices that starts and ends with the same vertex. A loop is a special case of a cycle in which a single arc begins and ends with the same vertex. In a loop, the end points of the edge are the same. Data Structures: A Pseudocode Approach with C, Second Edition

A graph is disjoint if it is not connected. Two vertices are said to be connected if there is a path between them. A graph is said to be connected if, suppressing direction, there is a path from any vertex to any other vertex. A directed graph is strongly connected if there is a path from each vertex to every other vertex in the digraph. A directed graph is weakly connected when there are at least two vertices that are not connected. A graph is disjoint if it is not connected. The degree of a vertex is the number of lines incident to it. The outdegree of a vertex in a digraph is the number of arcs leaving the vertex. The indegree is the number of arcs entering the vertex. Data Structures: A Pseudocode Approach with C, Second Edition

11-2 Operations Insert Vertex Delete Vertex Add Edge Delete Edge We define and discuss the six primitive graph operations required to maintain a graph. Insert Vertex Delete Vertex Add Edge Delete Edge Find Vertex Traverse Graph Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

We begin by pushing the 1st vertex, A, into the stack. We then loop, popping the stack and after processing the vertex, pushing all of the adjacent vertices into the stack. To process X at step 2, we pop X from the stack, process it and then push G and H into the stack giving the stack contents for step 3 to process H and G. When the stack is empty, the traversal is complete. Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

We begin by enqueuing vertex, A, in the queue. We then loop, dequeuing the queue and processing the vertex from the front of the queue. After processing the vertex, we place all of its adjacent vertices into the queue. We are then ready for the next step. When the queue is empty, the traversal is complete. Data Structures: A Pseudocode Approach with C, Second Edition

11-3 Graph Storage Structures To represent a graph, we need to store two sets. The first set represents the vertices of the graph, and the second set represents the edges or arcs. The two most common structures used to store these sets are arrays and linked lists. Adjacency Matrix Adjacency List Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

11-6 Networks Minimum Spanning Tree Shortest Path Algorithm A network is a graph whose lines are weighted. It is also known as a weighted graph. Included in this section are two graph applications that process networks. Minimum Spanning Tree Shortest Path Algorithm Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

Minimum Spanning Tree A spanning tree is a tree that contains all of the vertices in a graph. A minimum spanning tree is a spanning tree in which the total weight of the lines are guaranteed to be the minimum of all possible trees in the graph. If the weights are unique, then there will be only one minimum spanning tree. Data Structures: A Pseudocode Approach with C, Second Edition

Algorithm of MST (Prim Algoritm) 1. Insert the first vertex (pick any vertex) into the tree 2. From every vertices already in the tree, examine the edges that connected to all adjacent vertices not in the tree. Select the edge with the minimum weight to a vertex not currently in the tree. Insert that minimum-weight edge and the vertex into the tree. 3. Repeat step 2 until all vertices are in the tree. Data Structures: A Pseudocode Approach with C, Second Edition

Data Structures: A Pseudocode Approach with C, Second Edition

(continued) Data Structures: A Pseudocode Approach with C, Second Edition