Breadth First search and Depth First search Finding connected components
|
|
- Erin George
- 5 years ago
- Views:
Transcription
1 Breadth First search and Depth First search Finding connected components Biswadeep Ghosh March 15,
2 Contents 1 Binary Image 4 2 Graphs Definition Example Adjacency Matrix Path Chain Connected Component Cycle,Tree Tree,Forest Spanning Tree Queue 11 4 stack 12 5 Breadth-first search algorithm algorithm Depth-first search algorithm Properties of BFS and DFS 14 8 Neighbourhood of a pixel neighbour Diagonal-neighbour neighbour Adjacency adjacent adjacent Path Connected Components Connected Component Labeling Connected Component Labeling Algorithms Connected Component Labelling by DFS Connected Component Labelling by BFS Runtime 22 2
3 13 Implementation Application 24 3
4 1 Binary Image Binary image is a digital image which has only two values for each pixel. Typically two colours used for binary images are black and white. The colour used for objects in a binary image is foreground while the rest of the image are background. Binary images are also known as two-level of bi-level. This means each image is stored in a single bit - i.e. a 0 or 1. The names black-white,monochromatic,monochrome are used for this concept. Figure 1:Example of a binary image:monalisa Binary images arises in certain applications. 2 Graphs Graphs are used to give representation to the problems where the item and there is interrelation between them.in graph theory,items and relations are represented by vertices and edges respectively. 2.1 Definition A graph G = (V, E) is a set of vertices V and there interrelationships are given by the set of edges E. If there is an orientation with respect to any edge then the graph is said to be directed otherwise undirected. An edge connecting two vertices x and y of a graph G is denoted by (x, y).if (x, y) is a directed edge, then it is oriented from vertex x to vertex y.if (x, y) is an undirected edge, then (x, y) = (y, x). 4
5 2.2 Example Consider the set of five vertices V = 1, 2, 3, 4, 5 and consider the direct adjacency relationships where a location is visible from one another.the summary is given in the following table. Location V isiblelocation 1 2, 3, , 3 The graph representation of this data is shown in the figure below.here the set of vertices are given by V = 1, 2, 3, 4, 5. These are the set of locations. Vertices are represented by the circles in the figure. The set of edges corresponds to the interrelationships between the set of visibility vertices. An edge (u, v) exists if vertex v is visible from the vertex u. The set of edges are given by (1, 2), (1, 3), (1, 4), (2, 3), (3, 5), (4, 1), (4, 3). The Directed and undirected graphs are shown below. Figure 2: Graph (a) Directed Version 5
6 2.3 Adjacency Matrix Figure 3: Graph (a) Undirected Version Definition: A graph G = (V, E) where V = v 0, v 1,, v n 1 can be represented by an adjacency matrix M (G). = (m ij ) i=0,,n 1,j=0,,n 1 defined by, 1, if (v i, v j ) ɛ E. m ij = (1) 0, otherwise. It may be noted that the adjacency matrix of an undirected graph is symmetric. Continuing with the above example the adjacency matrix shown in the figure 2 of the directed graph is given below, and the adjacency matrix shown in figure 3 for the undirected graph is given below,
7 2.4 Path Definition:Given a graph G = (V, E), Let u ɛ V and v ɛ V, then a path from u to v is a sequence of vertices P uv = a 0, a 1, a 2,, a n where a 0 = u and a n = v, such that (a i, a i+1 ) ɛ E, for i = 0,, n 1. In the specific instances where each vertex is visited exactly once, the path is called a simple path.i.e, 2.5 Chain a i a j,for any pair of distinct vertices u i, u j P uv If the edges in this path are undirected, then this undirected path is known as a chain. 2.6 Connected Component Definition: A connected component is a graph G = (V, E) such that there exist a chain between any two vertices in Ḡ = ( V, Ē ). A special type of path is a cycle. 2.7 Cycle,Tree Definition: A cycle is path from a vertex v of a graph G = (V, E) to itself.clearly, a cycle is a closed path. Tree: A tree is a graph without a cycle. For example, in the above graph, there is a cycle at the vertex Tree,Forest A directed tree T = (V, E) rooted at vertex r ɛ V is a directed connected component such that there exist a unique directed path from root r to any other vertex ɛ V. A undirected tree T = (V, E) is a undirected connected component without any cycle. In an undirected tree,each vertex can be considered as a root. A set of trees is called a forest. Some examples of Tree and Forest is shown in the following figures. 7
8 Fig 4: Example of a Tree Fig 5: Example of a Forest 8
9 2.9 Spanning Tree Definition: Given a undirected graph G = (V, E), the spanning tree T is a subgraph which contain the minimum possible no of edges of G. A graph can have several spanning trees. A spanning tree of a graph G can also be defined as the subgraph of G which has maximal set of edges which don t contain any cycle. Spanning trees of a graph may not be unique. Consider the following the graph Fig 6: Another example The graph has four spanning trees shown in the following images. Fig 7: 1st spanning Tree 9
10 Fig 8: 2nd spanning Tree Fig 9: 3rd spanning Tree 10
11 Fig 10: 4th spanning Tree Here we have shown examples of spanning tree for undirected graph, but spanning tree of directed graphs also exist. There are two algorithms namely Depth First Search and Breadth First Search to find the connected components of a given graph. 3 Queue Queue is a special type of data structure. In a Queue, the element deleted always is that has been longest time in the Queue. The Queue implements the FIFO property first-in,first-out. The Insert operation in a Queue is known as ENQUEUE and the delete operation is known as DEQUEUE. The FIFO property resembles the Queue like a line of customers waiting to enter a shop. Likewise, when a new customer comes, he stands at the end of the line and when a customer comes out of the shop, He exits from the beginning of the line, when a new element is added in the Queue,it places at the tail of the queue and when an element is dequeued from the Queue, then the element is deleted from the head of the Queue. We will use the terms front and rear for start and end of a Queue. The algorithm for ENQUEUE and DEQUEUE on the array Q[1, 2,, n]is given below, ENQUEUE(Q, x) if is. full (Q) == " true " return " Overflow " else rear = rear + 1 Q[ rear ] = x DEQUEUE(Q) 11
12 if is. empty (Q) == " true " return " Underflow " else data = Q[ front ] front = front + 1 return data is.empty(q) if front == rear return " true " else return " false " is.full(q) if rear == length ( Q) return " true " else return " false " 4 stack The stack is a type of dynamic set where the insert and delete operation is prespecified. The stack is based of LIFO property,i.e, Last in first out. The insert and delete operations are known as push and pop respectively.it resembles like putting a new book on a heap of books and if we want to remove a book we have to first remove the last book put in the heap. The algorithms for push pop are given below, where we implement the stack operation on an array S [1, 2,, n]. The stack consists of elements S [1, 2,, S.top],where S [S.top] is the element at the top. is.empty(s) if S. top == 0 return " true " else return " false " is.full(s) if S. top == n return " true " else return " false " push(s, x) if is. full (S) == " true " error " overflow " else S. top = S. top + 1 S[S. top ] = x pop(s, x) 12
13 if is. empty (S) == " true " error " underflow " else S. top = S. top - 1 return (S[S. top +1]) 5 Breadth-first search algorithm Breadth-first Search is one of graph search algorithms. Given a Graph G = (V, E) and a source vertex s, BFS explores the all reachable vertex starting from the source vertex s in a systematic manner.it computes the distance (smallest no of edges) of any reachable vertex from the sourse vertex s. Also, it produces the Breadth-first tree with root s including all possible vertex reachable from s. BFS starts from the initial node s and then check all of it s neighbours until all of neighbours of the source node s has been visited. Then it moves down to the first neighbour and visits all of it s neighbours and so on. If we imagine that the source node is at level 0, then it s immediate neighbours at level 1 and so on, then we observe that the BFS visits all the vertices of level 1 and then all vertices of level 2 and so on. This is the reason why the algorithm is called so. 5.1 algorithm The Breadth-first search algorithm for graphs is written below The input for the algorithm is a graph G and a source vertex s. BFS(G,s) for each vertex v \ in G. V visited [v] = " false " Q = EmptyQueue visited [s] = " true " Enqueue (Q, s) While ( not empty Q) u = Dequeue ( Q) for each vertex w in adj [ u] if not visited [ w] visited [w] = " true " Enqueue (Q, w) 6 Depth-first search Depth-first Search is also another graph search algorithm like Breadth-first Search. As the name suggests, It visits deeper to search the vertices. DFS explores edges out of most recently discovered vertex v that has unexplored edges leaving it. Once all of the edges of the v has been explored, the search backtracks to explore the edges leaving the vertex from which v is discovered. This process continues until there are vertices reachable from the source vertex of the given graph. 13
14 Like BFS, DFS also produces a spanning tree of the input graph known as Depth-first search Tree. 6.1 algorithm The Depth-first search algorithm for graphs is written below The input for the algorithm is a graph G and a source vertex s. Following is the non-recursive version. DFS(G,s) for each vertex v \ in G. V visited [v] = " false " S = EmptyStack visited [s] = " true " push (S,s) While ( not empty S) u = pop (S) for each vertex w in adj [ u] if not visited [ w] visited [w] = " true " push (Q,w) Recursive version is given below. DFS(G,s) label v as discovered for all vertices w belonging to adjacent ( v) if w is undiscovered DFS (G,w) 7 Properties of BFS and DFS Both BFS and DFS are used to find all vertices reachable from a given source vertex.but, they have some different characteristics noted below. BFS starts traversal from the root node and search in the level by level manner i.e, as close as possible from the root node. on the other hand,dfs starts traversal from the root node and explore the search as far deep as possible. BFS can be implemented using a Queue. on the other hand,dfs can be implemented by a Stack. BFS works in a single stage as visited vertices are removed from the queue and displayed once. But DFS works in two stages. In first stage the vertices discovered are put into the stack and in the second stage, there is no vertex to visit which are popped. Consider the following example, 14
15 The set of vertices visited by BFS is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 The set of vertices visited by DFS is 0, 1, 2, 3, 6, 7, 8, 9, 4, 5 8 Neighbourhood of a pixel Given a pixel of a binary image, there can be different types of neighbourhoods neighbour Given a binary image, let an arbitary pixel be denoted by tuple (x, y). Then, the 4- neighbours of this pixel is denoted by N 4 (p) given by (x + 1, y),(x 1, y),(x, y 1),(x, y + 1). 8.2 Diagonal-neighbour Figure 11:4-neighbour of a pixel (x, y) The no of Diagonal-neighbour of pixel (x, y) is 4,denoted by N d (p) given by the following (x 1, y 1),(x 1, y + 1),(x + 1, y 1),(x + 1, y + 1). 15
16 8.3 8-neighbour Figure 12:Diagonal-neighbour of a pixel (x, y) The union of 4-neighbour and Diagonal-neighbour of the pixel (x, y) is known as 8-neighbour of the given pixel, denoted by N 8 (p) These are the following, (x + 1, y),(x 1, y),(x, y 1),(x, y + 1),(x 1, y 1),(x 1, y + 1),(x + 1, y 1),(x + 1, y + 1) Figure 13:8-neighbour of a pixel (x, y) 9 Adjacency Two pixels p and q are said to be Adjacent if one is present in the set of any type of neighbours of pixel p adjacent : If q is present in the set N 4 p, then q is called 4-adjacent adjacent : If q is present in the set N 8 p q is called 8-adjacent. 16
17 9.3 Path Analogous to the graph theory, Path can also be defined in context of binary images. Definition: A Path from pixel p with co-ordinates (x, y) to pixel q with co-ordinates (s, t) is a sequence (a 0, b 0 ), (a 1, b 2 ),, (a n, b n ) where (a 0, b 0 ) = (x, y) and (a n, b n ) = (s, t), where co-ordinates (a i, b i ) is adjacent to (a i+1, b i+1 ). 10 Connected Components Definition: Given a binary image B, a Connected Component with value v is a set of pixels C such that each pixel has value v and there is a path from a pixel to another pixel in the set C. Fig 14 shows four connected components of 1 s in a binary image fig 14: A binary image with four connected components 10.1 Connected Component Labeling Definition: A Connected Component Labeling of a binary image B is a image where value of each pixel is label of the component associated with it. For example, the Connected Component Labeling of the previous binary image is the following, fig 15: A binary image with Connected Component Labeling A label is a symbol that uniquely determines an entity. The Connected Component Labeling can be done using different characters but positive integers are mostly used to label connected components.for the display of images, the different labels is replaced by different colours of different graylevels. Now, let us see the corresponding binary image and the labeled image shown in following images. 17
18 fig 16: corresponding binary image fig 17: Labeled image 11 Connected Component Labeling Algorithms There are several Connected Component Labeling algorithms of a binary image is available like One Pass,Two Pass and Depth-first Search,Breadth-first Search etc. Here, we will concentrate only the Depth-first Search and Breadth-first Search algorithms. Here, our algorithms are based on 8-neighbour of a pixel and input binary matrix is M. 18
19 11.1 Connected Component Labelling by DFS neighour(k, l) x = -1,0,1,1,1,0, -1, -1 y = 1,1,1,0, -1, -1, -1,0 for (i = 1,...,8) n_k = k + x[ i] n_l = l + y[ i] PixelDFS(M, i, j, c, visited) M[i, j] = c # label the (i, j) th pixel visited [i, j] = " true " #( i, j) th pixel is visited for ( any (n_k, n_l ) belonging to neighbour (i,j)) if(m[n_k, n_l ] == 1) && ( visited [n_k, n_l ] == " false ") # visiting if a neighbour is black M[n_k, n_l ] = c # label the (n_k, n_l )th pixel visited [n_k, n_l ] = " true " #( n_k, n_l )th pixel is visited ConncomplabelDFS(M) set = 2 visited = " false " # create logical matrix of same dimension as M for (i = 1,2,.., no of row of M) for (j = 1,2,.., no of column of M) if ( M[i, j] == 1) & ( visited [i, j] == " false ") # visiting if (i, j) th pixel is black PixelDFS (M,i,j, set ++, visited ) # labelling the connected components for (i = 1,2,.., no of row of M) for (j = 1,2,.., no of column of M) if (M[i,j]!= 0) M[i, j] = M[i, j] - 1 return M 19
20 11.2 Connected Component Labelling by BFS PixelBFS(M, i, j, c, visited) Q_row = EmptyQueue # two empty queues for storing row and column indexes Q_col = EmptyQueue visited = " false " # Logical matrix of same dimenson as M, initially all element false M[i, j] = c # label the (i, j) th pixel visited [i, j] = " true " #( i, j) th pixel is visited Enqueue ( Q_row, i) # enqueueing indexes i and j Enqueue ( Q_col,j) while (( Q_row is empty )&( Q_col is empty )) k = Dequeue ( Q_row ) l = Dequeue ( Q_col ) for ( any (n_k, n_l ) belonging to neighbour (k,l)) if(m[n_k, n_l ] == 1) && ( visited [n_k, n_l ] == " false ")# visiting a black neighbour M[n_k, n_l ] = c # label the (n_k, n_l )th pixel visited [n_k, n_l ] = " true " #( n_k, n_l )th pixel is visited Enqueue ( Q_row, n_k ) Enqueue ( Q_col, n_l ) ConncomplabelBFS(M) visited = " false " # create logical matrix of same dimension as M set = 2 for (i = 1,2,.., no of row of M) for (j = 1,2,.., no of column of M) if ( M[i, j] == 1) & ( visited [i, j] == " false ") # visiting if (i, j) th pixel is black PixelBFS (M,i,j, set ++, visited ) # labelling the connected component # label increase by 1 for (i = 1,2,.., no of row of M) for (j = 1,2,.., no of column of M) if (M[i,j]!= 0) M[i, j] = M[i, j] - 1 return M 20
21 To find the no of connected components we use following algorithms NoCompDFS(M) set = 2 visited = " false " # create logical matrix of same dimension as M for (i = 1,2,.., no of row of M) for (j = 1,2,.., no of column of M) if ( M[i, j] == 1) & ( visited [i, j] == " false ") # visiting if (i, j) th pixel is black PixelDFS (M,i,j, set ++, visited ) # labelling the connected components count = set - 2 return count NoCompBFS(M) set = 2 visited = " false " # create logical matrix of same dimension as M for (i = 1,2,.., no of row of M) for (j = 1,2,.., no of column of M) if ( M[i, j] == 1) & ( visited [i, j] == " false ") # visiting if (i, j) th pixel is black PixelBFS (M,i,j, set ++, visited ) # labelling the connected components count = set - 2 return count 21
22 12 Runtime the runtime graph on connected component by DFS,BFS,ConnCompLabel function in R as follows, Runtime graph of three methods 13 Implementation Three algorithms discussed above is based on 8-neighbour of a pixel. We can implement any of the three algorithms in following successive steps written below, Given a binary image,say B,of dimension m n It is scanned to get a binary matrix,say M of same dimensions, where the 1 denotes the black pixel of the image and 0 indicates the white pixel present of the image. Then, the matrix M is augmented by two zero rows and two zero columns, this is done to make so that we can apply any of the two algorithms which is based on 8-neighbour. Call this new matrix as A. Now, apply any one of the three connected component labeling algorithm. Call the output labelled matrix as L, which is of dimension (m + 2) (n + 2). Now, select the submatrix of L, where the set of rows and set of columns are denoted by 2,3,,(m + 1) and 2,3,,(n + 1).Call this L M. 22
23 Now, from the final Labeled image L M, we can easily get the coloured image where the connected components present in the input image is identified by separate colours.here is an little application using ConnCompLabelDFS algorithm. Consider the image of monalisa, Fig 18: Monalisa image Binary The corresponding Labelled image(graylablled) is given below, Fig 19: Monalisa image labelled(graylabelled) 23
24 This is done by following R-code library ( EBImage ) library ( Rcpp ) library ( bmp ) sourcecpp (" dfs _ ccl. cpp ") B <- read. bmp (" monalisa. bmp ") #to scan the bitmap image C_1 <- B[,,1] C <- binary ( C_ 1) # to make image matrix binary x <- ncol (C) y <- nrow (C) C <- rbind ( rep (0, x),c) # augmenting two zero rows C <- rbind (C,rep (0,x)) C <- cbind ( rep (0, y +2),C) # augmenting two zero columns C <- cbind (C,rep (0,y +2) ) display ( t( C)) # to display the binary image D <- connlabel _ 1( C) # Labelling the connected components of augmented matrix E <- D [2:( nrow (D) -1),2:( ncol (D) -1)] # taking the proper submatrix display ( t( E)/ max ( E) # display the graylabelled image 14 Application Binary image connected component labelling has several applications. One of important application is to count the no of objects present in the image or distinguish the components separately from other. Consider the following example, consider the image,
25 consider the labelled image, So, there are 8 different components peresent in the image References [1] [2] Binary Digital Image Processing- S. Marchand-Maillet,Y.M. Sharaiha [3] Introduction to Algorithms- Thomas H.Cormen et al. 25
Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)
Graph Algorithms Graphs Graph G = (V, E) V = set of vertices E = set of edges (V V) Types of graphs Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.) Directed: (u, v) is edge from
More informationElementary Graph Algorithms
Elementary Graph Algorithms Graphs Graph G = (V, E)» V = set of vertices» E = set of edges (V V) Types of graphs» Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.)» Directed: (u, v)
More informationCOT 6405 Introduction to Theory of Algorithms
COT 6405 Introduction to Theory of Algorithms Topic 14. Graph Algorithms 11/7/2016 1 Elementary Graph Algorithms How to represent a graph? Adjacency lists Adjacency matrix How to search a graph? Breadth-first
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
s of s Computer Science & Engineering 423/823 Design and Analysis of Lecture 03 (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 29 s of s s are abstract data types that are applicable
More informationLecture 9 Graph Traversal
Lecture 9 Graph Traversal Euiseong Seo (euiseong@skku.edu) SWE00: Principles in Programming Spring 0 Euiseong Seo (euiseong@skku.edu) Need for Graphs One of unifying themes of computer science Closely
More informationGraph Theory. Many problems are mapped to graphs. Problems. traffic VLSI circuits social network communication networks web pages relationship
Graph Graph Usage I want to visit all the known famous places starting from Seoul ending in Seoul Knowledge: distances, costs Find the optimal(distance or cost) path Graph Theory Many problems are mapped
More informationGraph: representation and traversal
Graph: representation and traversal CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang! Acknowledgement The set of slides have use materials from the following resources Slides for textbook
More informationMinimum Spanning Trees Ch 23 Traversing graphs
Next: Graph Algorithms Graphs Ch 22 Graph representations adjacency list adjacency matrix Minimum Spanning Trees Ch 23 Traversing graphs Breadth-First Search Depth-First Search 11/30/17 CSE 3101 1 Graphs
More informationRepresentations of Graphs
ELEMENTARY GRAPH ALGORITHMS -- CS-5321 Presentation -- I am Nishit Kapadia Representations of Graphs There are two standard ways: A collection of adjacency lists - they provide a compact way to represent
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms CSE 5311 Lecture 18 Graph Algorithm Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 Graphs Graph G = (V,
More informationBasic Graph Algorithms
Basic Graph Algorithms 1 Representations of Graphs There are two standard ways to represent a graph G(V, E) where V is the set of vertices and E is the set of edges. adjacency list representation adjacency
More informationUNIT IV -NON-LINEAR DATA STRUCTURES 4.1 Trees TREE: A tree is a finite set of one or more nodes such that there is a specially designated node called the Root, and zero or more non empty sub trees T1,
More informationTIE Graph algorithms
TIE-20106 239 11 Graph algorithms This chapter discusses the data structure that is a collection of points (called nodes or vertices) and connections between them (called edges or arcs) a graph. The common
More informationCS 220: Discrete Structures and their Applications. graphs zybooks chapter 10
CS 220: Discrete Structures and their Applications graphs zybooks chapter 10 directed graphs A collection of vertices and directed edges What can this represent? undirected graphs A collection of vertices
More informationGraph Representation
Graph Representation Adjacency list representation of G = (V, E) An array of V lists, one for each vertex in V Each list Adj[u] contains all the vertices v such that there is an edge between u and v Adj[u]
More informationPractical Session No. 12 Graphs, BFS, DFS, Topological sort
Practical Session No. 12 Graphs, BFS, DFS, Topological sort Graphs and BFS Graph G = (V, E) Graph Representations (V G ) v1 v n V(G) = V - Set of all vertices in G E(G) = E - Set of all edges (u,v) in
More informationOutlines: Graphs Part-2
Elementary Graph Algorithms PART-2 1 Outlines: Graphs Part-2 Graph Search Methods Breadth-First Search (BFS): BFS Algorithm BFS Example BFS Time Complexity Output of BFS: Shortest Path Breath-First Tree
More informationData Structures. Elementary Graph Algorithms BFS, DFS & Topological Sort
Data Structures Elementary Graph Algorithms BFS, DFS & Topological Sort 1 Graphs A graph, G = (V, E), consists of two sets: V is a finite non-empty set of vertices. E is a set of pairs of vertices, called
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 04 Elementary Graph Algorithms (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu Introduction
More informationLecture 10. Elementary Graph Algorithm Minimum Spanning Trees
Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo
More informationTIE Graph algorithms
TIE-20106 1 1 Graph algorithms This chapter discusses the data structure that is a collection of points (called nodes or vertices) and connections between them (called edges or arcs) a graph. The common
More informationFundamental Algorithms
Fundamental Algorithms Chapter 8: Graphs Jan Křetínský Winter 2017/18 Chapter 8: Graphs, Winter 2017/18 1 Graphs Definition (Graph) A graph G = (V, E) consists of a set V of vertices (nodes) and a set
More informationCS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs
CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs 5 3 2 4 1 0 2 Graphs A graph G = (V, E) Where V is a set of vertices E is a set of edges connecting vertex pairs Example: V = {0, 1, 2, 3, 4, 5} E = {(0, 1),
More informationCSE 100: GRAPH ALGORITHMS
CSE 100: GRAPH ALGORITHMS 2 Graphs: Example A directed graph V5 V = { V = E = { E Path: 3 Graphs: Definitions A directed graph V5 V6 A graph G = (V,E) consists of a set of vertices V and a set of edges
More informationGraph Algorithms. Definition
Graph Algorithms Many problems in CS can be modeled as graph problems. Algorithms for solving graph problems are fundamental to the field of algorithm design. Definition A graph G = (V, E) consists of
More informationCS 310 Advanced Data Structures and Algorithms
CS 31 Advanced Data Structures and Algorithms Graphs July 18, 17 Tong Wang UMass Boston CS 31 July 18, 17 1 / 4 Graph Definitions Graph a mathematical construction that describes objects and relations
More informationGraph Algorithms: Chapters Part 1: Introductory graph concepts
UMass Lowell Computer Science 91.503 Algorithms Dr. Haim Levkowitz Fall, 2007 Graph Algorithms: Chapters 22-25 Part 1: Introductory graph concepts 1 91.404 Graph Review Elementary Graph Algorithms Minimum
More informationAbstract Data Types CHAPTER 12. Review Questions
PTR bstract ata Types Review Questions. n abstract data type is a data declaration packaged together with the operations that are meaningful for the data type with the implementation hidden from the user..
More informationElementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:
Elementary Graph Algorithms Ref: Chapter 22 of the text by Cormen et al. Representing a graph: Graph G(V, E): V set of nodes (vertices); E set of edges. Notation: n = V and m = E. (Vertices are numbered
More informationAlgorithms and Theory of Computation. Lecture 3: Graph Algorithms
Algorithms and Theory of Computation Lecture 3: Graph Algorithms Xiaohui Bei MAS 714 August 20, 2018 Nanyang Technological University MAS 714 August 20, 2018 1 / 18 Connectivity In a undirected graph G
More informationScribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.
Lecture 9 Graphs Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M. Wootters (2017) 1 Graphs A graph is a set of vertices
More informationCSI 604 Elementary Graph Algorithms
CSI 604 Elementary Graph Algorithms Ref: Chapter 22 of the text by Cormen et al. (Second edition) 1 / 25 Graphs: Basic Definitions Undirected Graph G(V, E): V is set of nodes (or vertices) and E is the
More informationGraph Search. Adnan Aziz
Graph Search Adnan Aziz Based on CLRS, Ch 22. Recall encountered graphs several weeks ago (CLRS B.4) restricted our attention to definitions, terminology, properties Now we ll see how to perform basic
More informationPractical Session No. 12 Graphs, BFS, DFS Topological Sort
Practical Session No. 12 Graphs, BFS, DFS Topological Sort Graphs and BFS Graph G = (V, E) Graph Representations (VG ) v1 v n V(G) = V - Set of all vertices in G E(G) = E - Set of all edges (u,v) in G,
More informationCS/COE
CS/COE 151 www.cs.pitt.edu/~lipschultz/cs151/ Graphs 5 3 2 4 1 Graphs A graph G = (V, E) Where V is a set of vertices E is a set of edges connecting vertex pairs Example: V = {, 1, 2, 3, 4, 5} E = {(,
More information22.1 Representations of graphs
22.1 Representations of graphs There are two standard ways to represent a (directed or undirected) graph G = (V,E), where V is the set of vertices (or nodes) and E is the set of edges (or links). Adjacency
More informationChapter 22 Elementary Graph Algorithms
Chapter 22 Elementary Graph Algorithms Graph Representations Graph G = (V,E) Directed Undirected Adjacency Lists Adjacency Matrix Graph Representations Adjacency List: Undirected Memory: Adjacency: Graph
More informationGraph representation
Graph Algorithms 1 Graph representation Given graph G = (V, E). May be either directed or undirected. Two common ways to represent for algorithms: 1. Adjacency lists. 2. Adjacency matrix. When expressing
More informationChapter 22. Elementary Graph Algorithms
Graph Algorithms - Spring 2011 Set 7. Lecturer: Huilan Chang Reference: (1) Cormen, Leiserson, Rivest, and Stein, Introduction to Algorithms, 2nd Edition, The MIT Press. (2) Lecture notes from C. Y. Chen
More informationGraph implementations :
Graphs Graph implementations : The two standard ways of representing a graph G = (V, E) are adjacency-matrices and collections of adjacencylists. The adjacency-lists are ideal for sparse trees those where
More informationData Structures and Algorithms. Chapter 7. Graphs
1 Data Structures and Algorithms Chapter 7 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples
More informationFigure 1: A directed graph.
1 Graphs A graph is a data structure that expresses relationships between objects. The objects are called nodes and the relationships are called edges. For example, social networks can be represented as
More informationAnnouncements Problem Set 4 is out!
CSC263 Week 8 Announcements Problem Set 4 is out! Due Tuesday (Nov 17) Other Announcements Drop date Nov 8 Final exam schedule is posted CSC263 exam Dec 11, 2-5pm This week s outline Graphs BFS Graph A
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 5 Exploring graphs Adam Smith 9/5/2008 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Puzzles Suppose an undirected graph G is connected.
More informationReview: Graph Theory and Representation
Review: Graph Theory and Representation Graph Algorithms Graphs and Theorems about Graphs Graph implementation Graph Algorithms Shortest paths Minimum spanning tree What can graphs model? Cost of wiring
More informationGraph Representations and Traversal
COMPSCI 330: Design and Analysis of Algorithms 02/08/2017-02/20/2017 Graph Representations and Traversal Lecturer: Debmalya Panigrahi Scribe: Tianqi Song, Fred Zhang, Tianyu Wang 1 Overview This lecture
More informationThis course is intended for 3rd and/or 4th year undergraduate majors in Computer Science.
Lecture 9 Graphs This course is intended for 3rd and/or 4th year undergraduate majors in Computer Science. You need to be familiar with the design and use of basic data structures such as Lists, Stacks,
More informationGraph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1
Graph Algorithms Chapter 22 CPTR 430 Algorithms Graph Algorithms Why Study Graph Algorithms? Mathematical graphs seem to be relatively specialized and abstract Why spend so much time and effort on algorithms
More informationTrees Algorhyme by Radia Perlman
Algorhyme by Radia Perlman I think that I shall never see A graph more lovely than a tree. A tree whose crucial property Is loop-free connectivity. A tree which must be sure to span. So packets can reach
More informationLECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS
Department of Computer Science University of Babylon LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS By Faculty of Science for Women( SCIW), University of Babylon, Iraq Samaher@uobabylon.edu.iq
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 04 / 06 / 2018 Instructor: Michael Eckmann Today s Topics Questions? Comments? Graphs Definition Terminology two ways to represent edges in implementation traversals
More informationChapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1
Chapter 14 Graphs 2011 Pearson Addison-Wesley. All rights reserved 14 A-1 Terminology G = {V, E} A graph G consists of two sets A set V of vertices, or nodes A set E of edges A subgraph Consists of a subset
More informationName CPTR246 Spring '17 (100 total points) Exam 3
Name CPTR246 Spring '17 (100 total points) Exam 3 1. Linked Lists Consider the following linked list of integers (sorted from lowest to highest) and the changes described. Make the necessary changes in
More informationLecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this
Lecture Notes Array Review An array in C++ is a contiguous block of memory. Since a char is 1 byte, then an array of 5 chars is 5 bytes. For example, if you execute the following C++ code you will allocate
More informationCS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019
CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
s of s Computer Science & Engineering 423/823 Design and Analysis of Lecture 03 (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 29 Spring 2010 s of s s are abstract data types that
More informationMultidimensional Arrays & Graphs. CMSC 420: Lecture 3
Multidimensional Arrays & Graphs CMSC 420: Lecture 3 Mini-Review Abstract Data Types: List Stack Queue Deque Dictionary Set Implementations: Linked Lists Circularly linked lists Doubly linked lists XOR
More informationTrees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006
Trees and Graphs Basic Definitions Tree: Any connected, acyclic graph G = (V,E) E = V -1 n-ary Tree: Tree s/t all vertices of degree n+1 A root has degree n Binary Search Tree: A binary tree such that
More informationECE250: Algorithms and Data Structures Elementary Graph Algorithms Part A
ECE250: Algorithms and Data Structures Elementary Graph Algorithms Part A Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp.
More informationJana Kosecka. Red-Black Trees Graph Algorithms. Many slides here are based on E. Demaine, D. Luebke slides
Jana Kosecka Red-Black Trees Graph Algorithms Many slides here are based on E. Demaine, D. Luebke slides Binary Search Trees (BSTs) are an important data structure for dynamic sets In addition to satellite
More informationCSC263 Week 8. Larry Zhang.
CSC263 Week 8 Larry Zhang http://goo.gl/forms/s9yie3597b Announcements (strike related) Lectures go as normal Tutorial this week everyone go to BA32 (T8, F2, F2, F3) Problem sets / Assignments are submitted
More informationData Structures and Algorithms. Werner Nutt
Data Structures and Algorithms Werner Nutt nutt@inf.unibz.it http://www.inf.unibz/it/~nutt Part 9 Academic Year 2011-2012 1 Acknowledgements & Copyright Notice These slides are built on top of slides developed
More informationInf 2B: Graphs, BFS, DFS
Inf 2B: Graphs, BFS, DFS Kyriakos Kalorkoti School of Informatics University of Edinburgh Directed and Undirected Graphs I A graph is a mathematical structure consisting of a set of vertices and a set
More informationSolutions to Midterm 2 - Monday, July 11th, 2009
Solutions to Midterm - Monday, July 11th, 009 CPSC30, Summer009. Instructor: Dr. Lior Malka. (liorma@cs.ubc.ca) 1. Dynamic programming. Let A be a set of n integers A 1,..., A n such that 1 A i n for each
More informationA6-R3: DATA STRUCTURE THROUGH C LANGUAGE
A6-R3: DATA STRUCTURE THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered in the TEAR-OFF
More informationBasic Graph Algorithms (CLRS B.4-B.5, )
Basic Graph Algorithms (CLRS B.-B.,.-.) Basic Graph Definitions A graph G = (V,E) consists of a finite set of vertices V and a finite set of edges E. Directed graphs: E is a set of ordered pairs of vertices
More informationI A graph is a mathematical structure consisting of a set of. I Formally: G =(V, E), where V is a set and E V V.
Directed and Undirected Graphs Inf 2B: Graphs, BFS, DFS Kyriakos Kalorkoti School of Informatics University of Edinburgh I A graph is a mathematical structure consisting of a set of vertices and a set
More informationComputational Optimization ISE 407. Lecture 19. Dr. Ted Ralphs
Computational Optimization ISE 407 Lecture 19 Dr. Ted Ralphs ISE 407 Lecture 19 1 Search Algorithms Search algorithms are fundamental techniques applied to solve a wide range of optimization problems.
More informationTrees. Arash Rafiey. 20 October, 2015
20 October, 2015 Definition Let G = (V, E) be a loop-free undirected graph. G is called a tree if G is connected and contains no cycle. Definition Let G = (V, E) be a loop-free undirected graph. G is called
More informationDARSHAN INST. OF ENGG. & TECH.
(1) Explain with example how games can be formulated using graphs? Consider the following game. It is one of the many variants of Nim, also known as the Marienbad game. Initially there is a heap of matches
More informationUNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list
UNIT-4 Graph: Terminology, Representation, Traversals Applications - spanning trees, shortest path and Transitive closure, Topological sort. Sets: Representation - Operations on sets Applications. 1. Name
More informationSome major graph problems
CS : Graphs and Blobs! Prof. Graeme Bailey http://cs.cs.cornell.edu (notes modified from Noah Snavely, Spring 009) Some major graph problems! Graph colouring Ensuring that radio stations don t clash! Graph
More informationTopic 12: Elementary Graph Algorithms
Topic 12: Elementary Graph Algorithms Pierre Flener Lars-enrik Eriksson (version of 2013-02-10) Different kinds of graphs List Tree A B C A B C Directed Acyclic Graph (DAG) D A B C D E Directed Graph (Digraph)
More informationCSE 100: GRAPH SEARCH
CSE 100: GRAPH SEARCH Announcements PA3 released Checkpoint due Tuesday, May 5 @10:00pm Final submission due Thursday, May 14 @10:00PM Start early! Start early! Start early! Start early! Start early! I
More informationLecture 3: Stacks & Queues
Lecture 3: Stacks & Queues Prakash Gautam https://prakashgautam.com.np/dipit02/ info@prakashgautam.com.np 22 March, 2018 Objectives Definition: Stacks & Queues Operations of Stack & Queues Implementation
More informationCS473-Algorithms I. Lecture 14-A. Graph Searching: Breadth-First Search. Cevdet Aykanat - Bilkent University Computer Engineering Department
CS473-Algorithms I Lecture 14-A Graph Searching: Breadth-First Search 1 Graph Searching: Breadth-First Search Graph G =(V, E), directed or undirected with adjacency list repres. GOAL: Systematically explores
More informationGraph: representation and traversal
Graph: representation and traversal CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Acknowledgement The set of slides have use materials from the following resources Slides for textbook
More informationGraph. Vertex. edge. Directed Graph. Undirected Graph
Module : Graphs Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS E-mail: natarajan.meghanathan@jsums.edu Graph Graph is a data structure that is a collection
More informationGraphs. Graphs. Representation of Graphs. CSE 680 Prof. Roger Crawfis. Two standard ways. Graph G = (V, E)» V = set of vertices
Introduction to Algorithms Graph Algorithms CSE 680 Prof. Roger Crawfis Partially from io.uwinnipeg.ca/~ychen2 Graphs Graph G = (V, E)» V = set of vertices» E = set of edges (V V) V) Types of graphs» Undirected:
More informationINSTITUTE OF AERONAUTICAL ENGINEERING
INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech
More informationGraphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington
Graphs CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington 1 Representation Adjacency matrix??adjacency lists?? Review Graphs (from CSE 2315)
More informationGraph Algorithms Using Depth First Search
Graph Algorithms Using Depth First Search Analysis of Algorithms Week 8, Lecture 1 Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Graph Algorithms Using Depth
More informationUniversity of Illinois at Urbana-Champaign Department of Computer Science. Final Examination
University of Illinois at Urbana-Champaign Department of Computer Science Final Examination CS 225 Data Structures and Software Principles Spring 2010 7-10p, Wednesday, May 12 Name: NetID: Lab Section
More informationCS 1114: Implementing Search. Last time. ! Graph traversal. ! Two types of todo lists: ! Prof. Graeme Bailey.
CS 1114: Implementing Search! Prof. Graeme Bailey http://cs1114.cs.cornell.edu (notes modified from Noah Snavely, Spring 2009) Last time! Graph traversal 1 1 2 10 9 2 3 6 3 5 6 8 5 4 7 9 4 7 8 10! Two
More informationThe ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value
The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value 1 Possible implementations Sorted linear implementations o Appropriate if
More informationCHAPTER 23: ELEMENTARY GRAPH ALGORITHMS Representations of graphs
CHAPTER 23: ELEMENTARY GRAPH ALGORITHMS This chapter presents methods for representing a graph and for searching a graph. Searching a graph means systematically following the edges of the graph so as to
More informationUndirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1
Undirected Graphs Terminology. Free Trees. Representations. Minimum Spanning Trees (algorithms: Prim, Kruskal). Graph Traversals (dfs, bfs). Articulation points & Biconnected Components. Graph Matching
More informationPart VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths
Part VI Graph algorithms Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths 1 Chapter 22 Elementary Graph Algorithms Representations of graphs
More informationCS490: Problem Solving in Computer Science Lecture 6: Introductory Graph Theory
CS490: Problem Solving in Computer Science Lecture 6: Introductory Graph Theory Dustin Tseng Mike Li Wednesday January 16, 2006 Dustin Tseng Mike Li: CS490: Problem Solving in Computer Science, Lecture
More informationData Structure. IBPS SO (IT- Officer) Exam 2017
Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data
More information8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))
DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT IV NONLINEAR DATA STRUCTURES Part A 1. Define Tree [N/D 08]
More information12 Abstract Data Types
12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define
More information8. Fundamental Data Structures
172 8. Fundamental Data Structures Abstract data types stack, queue, implementation variants for linked lists, [Ottman/Widmayer, Kap. 1.5.1-1.5.2, Cormen et al, Kap. 10.1.-10.2] Abstract Data Types 173
More informationCS 270 Algorithms. Oliver Kullmann. Breadth-first search. Analysing BFS. Depth-first. search. Analysing DFS. Dags and topological sorting.
Week 5 General remarks and 2 We consider the simplest graph- algorithm, breadth-first (). We apply to compute shortest paths. Then we consider the second main graph- algorithm, depth-first (). And we consider
More informationCS8391-DATA STRUCTURES QUESTION BANK UNIT I
CS8391-DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Define data structure. The data structure can be defined as the collection of elements and all the possible operations which are required for those
More information22.3 Depth First Search
22.3 Depth First Search Depth-First Search(DFS) always visits a neighbour of the most recently visited vertex with an unvisited neighbour. This means the search moves forward when possible, and only backtracks
More informationGraph Traversal CSCI Algorithms I. Andrew Rosenberg
Graph Traversal CSCI 700 - Algorithms I Andrew Rosenberg Last Time Introduced Graphs Today Traversing a Graph A shortest path algorithm Example Graph We will use this graph as an example throughout today
More informationAnnouncements. HW3 is graded. Average is 81%
CSC263 Week 9 Announcements HW3 is graded. Average is 81% Announcements Problem Set 4 is due this Tuesday! Due Tuesday (Nov 17) Recap The Graph ADT definition and data structures BFS gives us single-source
More information1 P age DS & OOPS / UNIT II
UNIT II Stacks: Definition operations - applications of stack. Queues: Definition - operations Priority queues - De que Applications of queue. Linked List: Singly Linked List, Doubly Linked List, Circular
More informationCS 8391 DATA STRUCTURES
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK CS 8391 DATA STRUCTURES UNIT- I PART A 1. Define: data structure. A data structure is a way of storing and organizing data in the memory for
More information