Data Structures 13th Week

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Bioinformatics Programming 1 EE, NCKU Tien-Hao Chang (Darby Chang)
CHAPTER 6 GRAPHS All the programs in this file are selected from
Review Binary Search Trees Operations on Binary Search Tree
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graph Theory.
Chapter 6. Konigsberg Bridge Problem A river Pregel flows around the island Keniphof and then divides into two. Four land areas A, B, C, D have this river.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: 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.
CS Data Structures Chapter 6 Graphs.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
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.
GRAPH Learning Outcomes Students should be able to:
Data Structures Using C++ 2E
Graphs. Motivating Problem Konigsberg bridge problem (1736): Konigsberg bridge problem (1736): C A B D ab c d e f g Starting in one land area, is it possible.
Copyright Networking Laboratory Chapter 6. GRAPHS Horowitz, Sahni, and Anderson-Freed Fundamentals of Data Structures in C, 2nd Edition Computer.
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.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
Binary Search Trees Berlin Chen 陳柏琳 台灣師範大學資工系 副教授 參考資料來源:
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
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.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
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.
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.
Chapter 05 Introduction to Graph And Search Algorithms.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
Lecture #13. Topics 1.The Graph Abstract Data Type. 2.Graph Representations. 3.Elementary Graph Operations.
Leda Demos By: Kelley Louie Credits: definitions from Algorithms Lectures and Discrete Mathematics with Algorithms by Albertson and Hutchinson graphics.
BCA-II Data Structure Using C Submitted By: Veenu Saini
Data Structures & Algorithm Analysis lec(8):Graph T. Souad alonazi
Graphs Chapter 20.
Graphs Representation, BFS, DFS
Minimum Spanning Tree Chapter 13.6.
Csc 2720 Instructor: Zhuojun Duan
Introduction to Graphs
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
CS202 - Fundamental Structures of Computer Science II
CS120 Graphs.
CMSC 341 Lecture 21 Graphs (Introduction)
Graph Operations And Representation
CHAPTER 6 GRAPHS All the programs in this file are selected from
Graph Algorithm.
Graphs Representation, BFS, DFS
Graphs Chapter 13.
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.
Can you get there from here?
6.1.3 Graph representation.
Graphs.
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.
2017, Fall Pusan National University Ki-Joune Li
Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
ITEC 2620M Introduction to Data Structures
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
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.
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:

Data Structures 13th Week Chapter 6 Graphs 6.1 The Graph Abstract Data Type 6.2 Elementary Graph Operations 6.3 Minimum Cost Spanning Trees

The Graph Abstract Data Type A graph, G, consists of two sets : a finite, nonempty set of vertices, and a finite, possibly empty set of edges. V(G) and E(G) represent the sets of vertices and edges of G, respectively. Alternately, we may write G = (V, E) to represent a graph. Undirected graph is one in which the pair of vertices representing any edge is unordered. (v0, v1), (v1, v0) represent the same edge. Directed graph is one in which we represent each edge as a directed pair of vertices. <v0, v1> represents an edge in which v0 is the tail and v1 is the head.

Sample Graphs G1 G2 G3 V(G1) = {0, 1, 2, 3} E(G1) = {(0,1), (0,2), (0,3), (1,2), (1,3), (2,3)} V(G2) = {0, 1, 2, 3, 4, 5, 6} E(G2) = {(0,1), (0,2), (1,3), (1,4), (2,5), (2,6)} V(G3) = {0, 1, 2} E(G3) = {<0,1>, <1,0>, <1,2> }

Definitions complete graph adjacent, incident subgraph path graph that has the maximum number of edges. adjacent, incident if (v0, v1) is an edge in an undirected graph, then the vertices v0 and v1 are adjacent and the edge (v0, v1) is incident on vertices v0 and v1 subgraph a subgraph of G is a graph G’ such that V(G’ )  V(G) and E(G’)  E(G) path a path from vertex vp to vertex vq in a graph, G, is a sequence of vertices, vp, vi1, vi2, … , vin , vq such that (vp, vi1), (vi1, vi2), … , (vin , vq) are edges in an undirected graph.

the length of a path is the number of edges on it. simple path : path in which all vertices, except possibly the first and the last, are distinct. cycle : simple path in which the first and the last vertices are the same. connected In an undirected graph G, two vertices, v0 and v1, are connected if there is a path in G from v0 to v1. connected component : maximal connected subgraph tree : graph that is connected and a cyclic (it has no cycles). The degree of a vertex is the number of edges incident to the vertex.

restriction on graphs : 1. A graph may not have an edge from a vertex, i, back to itself. self loops. 2. A graph may not have multiple occurrences of the same edge. if we allow, multigraph.

Graph Representations Adjacency Matrix The adjacency matrix of G is a two-dimensional n  n array, say adj_mat. If the edge (vi, vj) ( <vi, vj> for a digraph) is in E(G), adj_mat[i][j] = 1. If there is no edge in E(G), adj_mat[i][j] = 0. ex)

Adjacency Lists replace the n rows of the adjacency matrix with n linked lists, one for each vertex in G. Ex)

Adjacency Multilists maintaining the lists as multilists, that is, lists in which nodes are shared among several lists, facilitates this operation. ex) The lists are : vertex 0 : N1  N2  N3 vertex 1 : N1  N4  N5 vertex 2 : N2  N4  N6 vertex 3 : N3  N5  N6

Depth First Search Algorithm 1. begin the search by visiting the start vertex, v. 2. select an unvisited vertex, w, from v’s adjacency list and carry out a depth first search on w. (using recursion)

Depth First Search Function #define FALSE 0 #define TRUE 1 short int visited[MAX_VERTICES]; void dfs(int v) { /* depth first search of a graph beginning with vertex v. */ node_pointer w; visited[v]=TRUE; printf(“5d”,v); for (w = graph[v]; w; w = w->link) if( !visited[w->vertex] ) dfs(w->vertex); }

ex) Depth first search order : v0, v1, v3, v7, v4, v5, v2, v6

Breadth First Search Algorithm 1. starts at vertex v and marks it as visited. 2. visits each of the vertices on v’s adjacency list. 3. when we have visited all the vertices on v’s adjacency list, we visit all the unvisited vertices that are adjacent to the first vertex on v’s adjacency list. using queue.

Connected Components whether or not an undirected graph is connected? Calling either dfs(0) of bfs(0) and then determining if there are any unvisited vertices. Listing the connected components of a graph. void connected(void) { /* determine the connected components of a graph */ int i; for ( i = 0; i < n; i++ ) if ( !visited[i] ) { dfs(i); printf(“\n”); }

Biconnected Components And Articulation Points Definition An articulation point is a vertex v of G such that the deletion of v, together with all edges incident on v, produces a graph, G’ that has at least two connected components. A biconnected graph is a connected graph that has no articulation points. A biconnected component of a connected undirected graph is a maximal biconnected subgraph, H, of G. The maximal biconnected subgraph means that G contains no other subgraph that is both biconnected and properly contains H.

ex) articulation point : 1, 3 ,5 ,7

Spanning Trees A spanning tree is any tree that consists solely of edge in G and that include all vertices in G. Use either dfs or bfs to create a spanning tree. depth first spanning tree breath first spanning tree

Minimum Cost Spanning Trees Definition cost of a spanning tree of a weighted undirected graph : the sum of the costs(weights) of the edges in the spanning tree Minimum cost spanning tree : a spanning tree of least cost Three algorithms for minimum cost spanning tree Kruskal’s, Prim’s, Sollin’s algorithms All three use an greedy method Greedy method At each stage, make a decision that is the best decision (using the criterion) Since we cannot change this decision later, we make sure that the decision will result in a feasible solution Typical criterion : least cost, highest profit criterion

Minimum Cost Spanning Trees (Cont’d) Greedy method At each stage, make a decision that is the best decision (using the criterion). Since we cannot change this decision later, we make sure that the decision will result in a feasible solution. Typical criterion : least cost, highest profit criterion Constraints for minimum cost spanning tree algorithms 1. Must use only edges within the graph. 2. Must use exactly n-1 edges. 3. May not use edges that would produce a cycle.

Kruskal’s Algorithm Methods build a minimum cost tree T by adding edges to T one at a time selects the edges for inclusion in T in nondecreasing order of their cost an edge is added in T if it does not form a cycle graph G is connected and has n>0 vertices, exactly n-1 edges will be selected

(Ex) Kruskal’s Algorithm