What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),

Slides:



Advertisements
Similar presentations
Depth-First Search1 Part-H2 Depth-First Search DB A C E.
Advertisements

CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Chapter 8, Part I Graph Algorithms.
Graph.
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 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
CS Data Structures Chapter 6 Graphs.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
GRAPHS Education is what remains after one has forgotten what one has learned in school. Albert Einstein Albert Einstein Smitha N Pai.
Graphs CS /02/05 Graphs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.
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.
Graph Theoretic Concepts. What is a graph? A set of vertices (or nodes) linked by edges Mathematically, we often write G = (V,E)  V: set of vertices,
Graphs Chapter 12.
Graphs1 Definitions Examples The Graph ADT LAX PVD LAX DFW FTL STL HNL.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
Spring 2007Graphs1 ORD DFW SFO LAX
CISC 235: Topic 9 Introduction to Graphs. CISC 235 Topic 92 Outline Graph Definition Terminology Representations Traversals.
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.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
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.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University Graphs Original Slides by Rada Mihalcea.
Lecture #13. Topics 1.The Graph Abstract Data Type. 2.Graph Representations. 3.Elementary Graph Operations.
Review Graph Directed Graph Undirected Graph Sub-Graph Spanning Sub-Graph Degree of a Vertex Weighted Graph Elementary and Simple Path Link List Representation.
Graphs ORD SFO LAX DFW Graphs 1 Graphs Graphs
CSC 172 DATA STRUCTURES.
BCA-II Data Structure Using C Submitted By: Veenu Saini
Data Structures & Algorithm Analysis lec(8):Graph T. Souad alonazi
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.
Directed Graphs Directed Graphs Shortest Path 12/7/2017 7:10 AM BOS
Directed Graphs 12/7/2017 7:15 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Graphs.
Data Structures Graphs - Terminology
Data Structures 13th Week
CMSC 341 Graphs.
Csc 2720 Instructor: Zhuojun Duan
COMP9024: Data Structures and Algorithms
COMP9024: Data Structures and Algorithms
Introduction to Graphs
Directed Graphs 9/20/2018 1:45 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
Directed Graphs 5/1/15 12:25:22 PM
CS120 Graphs.
Directed Graphs Directed Graphs 1 Shortest Path Shortest Path
CMSC 341 Lecture 21 Graphs (Introduction)
Graphs.
Graphs.
Graphs.
Graph Representation, DFS and BFS
Graphs CSE 2011 Winter November 2018.
Graphs All tree structures are hierarchical. This means that each node can only have one parent node. Trees can be used to store data which has a definite.
Elementary Graph Algorithms
Graphs.
Depth-First Search D B A C E Depth-First Search Depth-First Search
Depth-First Search Graph Traversals Depth-First Search DFS.
Graphs ORD SFO LAX DFW Graphs Graphs
Subgraphs, Connected Components, Spanning Trees
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Directed Graphs Directed Graphs Directed Graphs 2/23/ :12 AM BOS
Graphs Chapter 7 Visit for more Learning Resources.
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Elementary Graph Algorithms
GRAPHS.
CMSC 341 Graphs.
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:

What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d), A graph G = (V,E) is composed of: V: set of vertices E: set of edges connecting the vertices in V An edge e = (u,v) is a pair of vertices Example: a b V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d), (b,e),(c,d),(c,e), (d,e)} c d e

Applications electronic circuits CS16 networks (roads, flights, communications) LAX JFK DFW STL HNL FTL

Terminology: Degree of a Vertex The degree of a vertex is the number of edges incident to that vertex For directed graph, the in-degree of a vertex v is the number of edges that have v as the head the out-degree of a vertex v is the number of edges that have v as the tail

Examples 3 2 1 2 3 3 3 1 2 3 3 4 5 6 3 G1 1 1 G2 1 1 3 in:1, out: 1 directed graph in-degree out-degree 1 in: 1, out: 2 2 in: 1, out: 0 G3

Terminology: Path path: sequence of vertices v1,v2,. . .vk such that consecutive vertices vi and vi+1 are adjacent. 3 2 3 3 3 a b a b c c d e d e a b e d c b e d c

More Terminology simple path: no repeated vertices cycle: simple path, except that the last vertex is the same as the first vertex a b b e c c d e

Even More Terminology connected graph: any two vertices are connected by some path connected not connected subgraph: subset of vertices and edges forming a graph connected component: maximal connected subgraph. E.g., the graph below has 3 connected components.

(b) Some of the subgraph of G3 Subgraphs Examples 1 2 3 1 2 3 G1 (i) (ii) (iii) (iv) (a) Some of the subgraph of G1 1 2 1 2 (i) (ii) (iii) (iv) (b) Some of the subgraph of G3 G3

More… tree - connected graph without cycles forest - collection of trees

More Connectivity n = #vertices m = #edges For a tree m = n - 1

Oriented (Directed) Graph A graph where edges are directed

Directed vs. Undirected Graph An undirected graph is one in which the pair of vertices in a edge is unordered, (v0, v1) = (v1,v0) A directed graph is one in which each edge is a directed pair of vertices, <v0, v1> != <v1,v0> tail head

Graph Representations Adjacency Matrix Adjacency Lists

Adjacency Matrix Let G=(V,E) be a graph with n vertices. The adjacency matrix of G is a two-dimensional n by n array, say adj_mat If the edge (vi, vj) is in E(G), adj_mat[i][j]=1 If there is no such edge in E(G), adj_mat[i][j]=0

Examples for Adjacency Matrix 1 2 3 4 5 6 7 1 2 3 1 2 G2 G1 symmetric undirected: n2/2 directed: n2 G4

Merits of Adjacency Matrix From the adjacency matrix, to determine the connection of vertices is easy The degree of a vertex is For a digraph (= directed graph), the row sum is the out_degree, while the column sum is the in_degree

1 2 3 4 5 6 7 1 2 3 1 2 3 1 2 3 1 2 3 4 5 6 7 1 2 2 3 3 1 3 3 1 2 1 2 5 G1 4 6 1 2 1 5 7 2 1 6 G4 G3 2 An undirected graph with n vertices and e edges ==> n head nodes and 2e list nodes

Graph Traversal Problem: Search for a certain node or traverse all nodes in the graph Depth First Search Once a possible path is found, continue the search until the end of the path Breadth First Search Start several paths at a time, and advance in each one step at a time

Depth-First Search Algorithm DFS(v); Input: A vertex v in a graph Output: A labeling of the edges as “discovery” edges and “backedges” for each edge e incident on v do if edge e is unexplored then let w be the other endpoint of e if vertex w is unexplored then label e as a discovery edge recursively call DFS(w) else label e as a backedge

Breadth-First Search Like DFS, a Breadth-First Search (BFS) traverses a connected component of a graph, and in doing so defines a spanning tree with several useful properties. The starting vertex s has level 0, and, as in DFS, defines that point as an “anchor.” In the first round, the string is unrolled the length of one edge, and all of the edges that are only one edge away from the anchor are visited. These edges are placed into level 1 In the second round, all the new edges that can be reached by unrolling the string 2 edges are visited and placed in level 2. This continues until every vertex has been assigned a level. The label of any vertex v corresponds to the length of the shortest path from s to v.

BFS - A Graphical Representation d)

More BFS

BFS Pseudo-Code Algorithm BFS(s): Input: A vertex s in a graph Output: A labeling of the edges as “discovery” edges and “cross edges” initialize container L0 to contain vertex s i  0 while Li is not empty do create container Li+1 to initially be empty for each vertex v in Li do if edge e incident on v do let w be the other endpoint of e if vertex w is unexplored then label e as a discovery edge insert w into Li+1 else label e as a cross edge i  i + 1

DFS vs. BFS DFS Process found destination - done! start DFS Process E G D C destination D Call DFS on D C DFS on C B DFS on B B B Return to call on B A DFS on A A A A found destination - done! Path is implicitly stored in DFS recursion Path is: A, B, D, G G Call DFS on G D B A

DFS vs. BFS BFS Process found destination - done! start E BFS Process G D C destination rear front rear front rear front rear front A B D C D Initial call to BFS on A Add A to queue Dequeue A Add B Dequeue B Add C, D Dequeue C Nothing to add rear front G found destination - done! Path must be stored separately Dequeue D Add G