(Refer Slide Time: 02.06)

Size: px
Start display at page:

Transcription

1 Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 27 Depth First Search (DFS) Today we are going to be talking about depth first search. This is another way of searching a graph. In the previous class we looked at breadth first search. There are certain applications where depth first search is more meaningful than breadth first search and we are going to look at these application also. One application is the following. You are a mouse, you all know who you are. So you are a mouse and there has to be whatever something, carrot. No, I thought you said carrot, it was cat. There is a piece of cheese at the end of the maze and you have to find your way to this cheese. (Refer Slide Time: 02.06) This can be thought of as a graph in the following sense. At each of these squares I put down a vertex. We come to that in a minute. What will a mouse do? The mouse is not going to do a breadth first search unlikely that is going to do. It is not even going to do a depth first search but what it ends up doing is something like a depth first search. What this mouse is going to do as all other mice would is that it is going to go off in one direction. Try to explore that path, that direction fully and if it s not able to get to the cheese, it is going to try and backtrack. We will understand what all of that means.

2 Let s assume that our mouse has photogenic memory. When it comes back to the certain place, it knows that it has been at this place and it knows what path it took when it was in that place last time. We of course have data structures to keep track of this information but let s say mouse can also keep track of this. Let s say it started from here and it went down one step and it did not find its cheese. So it came down another step not yet, so let s say it decided to go right. Why? I don t know, it just decided to go right. It is said to go right and then it moved another step and at this point, it can only go down. It went down and again it came down here and lets say whenever it has option it can always goes right. It goes right again. Let s say that the mouse tries to take this direction first, east and then it tries to take this direction south and west and north. Now there is no doubt about left and right. It will try to go again east and did not find the cheese, so now it cannot go east, so it goes south and south and now it is stuck. It cannot go anywhere else because all the three sides are blocked but it can move, when it gets stuck like this it backtracks. Backtracks means goes back to the place where it came from. It goes back and at this point, it knows that it has been here before. It went south, so it now tries to go west but it cannot go west. So it has no other possibility but has to go back to where it came from and it came from here, so it goes back. Similarly here it goes back and it goes back. At this point when it reaches, it sees that it has another option which it has not explored which is going south. So it goes south now and then it comes here, it comes here. Now it will have no other option but to go west, west, north, north, north and now it comes to this point. It comes to this point but it sees that this is the point which it has been to before. It is already been to this place. It is not going to go to this point any more. If it has been at a particular cell before at a particular location before, it will not go there again because otherwise it will just keep going in a loop. It will not make any progress. Since it has been to this point before it will not go here. At this point it has no other option left, it cannot go east, it cannot go west. If it goes north, it goes to a place where it has been before. So it backtracks. At all of these points it will have to backtrack because there is nothing to be done and it comes back at this point. At this point it had explored the two options it had. The third option is not an option, it cannot go west so it will backtrack, backtrack, backtrack come here. Now here if it tries to go south, it sees well this is a place I have been to before. Why should I go there? It is after all just trying to find where the cheese is. If it has been to a place before there is no point going there again because it will then repeat the same sequence of steps. So it doesn t go here. That s one important thing that the mouse does and so it backtracks and backtrack and comes back to the starting position. What have we learnt? It is not so easy to find cheese. Now it will take the other option comes here, comes here, comes here, comes here, comes here, comes here. He said it will first try to go south, south, struck, backtrack, backtrack. At this point it has another option goes there, goes there, goes there, goes there and now it is a homerun. Time to clap, no.

3 It has found the cheese. This is what we will call depth first search and we will formalize this shortly. But this is fairly natural way of exploring. It is not artificial, you don t have to be a mouse to be doing this. You take a particular direction and you try to follow it till wherever it will reach till whatever you can, using that direction. So direction here now corresponds to in our graph sittings, it will correspond to taking one edge, going out along that edge to the next vertex and continuing and seeing where all you can reach. Then if you cannot reach any other vertex then you start backtracking. While there was a notion of goal here which was the cheese and you would stop here. In our depth first search there is no goal really. So our depth first search would just be a mechanism of exploring all the vertices of the graph. We will keep continuing our depth first search till we do not come back to the starting vertex and there are no other options left from the starting vertex so to say. (Refer Slide Time: 7:58) Our search is basically a method of visiting all the vertices with the graph. Now let me do a depth first search on a graph and show you what you get. I will start including some terminology now. This is the graph, we are working with an undirected graph for now. The notion of a depth first search is applicable also for directed graphs. So small simple graph and six vertices and I am starting from this vertex. So as in the case of breadth first search there is always a notion of a starting vertex. I am starting from this vertex. What am I going to do? I am going to take one edge out of this vertex. In the case of the mouse we choose a particular ordering. We said first we will take the option going east then south, then west, then north. Here we can choose whichever we want and typically we are going to take so recall we are working with the adjacency list implementation. For every node, so recall an adjacency list implementation, you have an array and for each vertex you have a linked list and this linked list is a list of adjacent vertices. The first edge I will consider is the edge going to the first vertex and when I have worked with this edge and I am explored everything, all the places I can reach with this end.

5 to backtrack out of this vertex. I backtrack out of this vertex at time nine. Backtrack out of this vertex at time nine and where do I end up? At this vertex. (Refer Slide Time: 15:48) So now reached this vertex. At this vertex I have explored this possibility, I have explored this possibility. I have not yet explored this possibility but this is meaningless because this vertex is already visited. I have explored all possibilities out of this vertex, so I now backtrack out of this. I backtrack out of this at time 10 and I come back to this vertex. At this vertex I have only explored this edge yet. Now I go explore this edge but this is going to a vertex which is already visited, so I cannot do anything. This is going to a vertex which is already visited so I cannot do anything. This is going to a vertex which is already visited, I cannot do anything. I am done with this vertex also. At time 11 I finish at this vertex. Each vertex is been given two numbers. The time at which we came there, the time at which we left, 6 vertices so there should be 12 numbers in all. (Refer Slide Time: 16.49) That s what we have 0 through 11. This procedure is called a depth first search. Any questions so far? Once again we will have a notion of black, grey and white vertices just as we had in the case of breadth first search. What should our initial color on the vertices be? White, unvisited same as breadth first search. When should I color a vertex grey? When I reach that node then I color it grey. When should I color it black? When I leave that node eventually then I should color it black. Is it clear to everyone? Same as in the breadth first search. When I had removed the node from the queue, when I inserted the node into the queue in breadth first search I color it grey. When I removed it from the queue I put its neighbors back into the queue. If any of the neighbors is white I put into the queue and I color this node black. So corresponding thing here would be when I backtrack from a node. I have explored all possibilities going out of that node then I color that node black. So if I am at a node, I will look at its neighbors and which neighbor will I go to?

6 Suppose this is the first neighbor I consider, in what circumstances, what should be the color of this neighbor so that I would go to this neighbor, white. Yet to be explored. Only if this node is white, will I go to this node. If it is black or grey then I will not go to this node at all. I am at this node, this is what I am saying. If this node is white only then do I explore it so to say. Let s understand this example a bit more. Let s mark out the edges along which we traveled in the course of our breadth first search with red. I travel along this edge because I came from here to here along this edge, how did I reach two from this one? I traveled along this edge, so once I went along this edge then I backtracked along this edge. Then I went along this edge then I went along this edge, then I backtracked along this edge. Then I went along this edge, backtracked along this, backtracked along this, backtracked along this. Each one of these red edges, I have went along them twice. Once I went along the edge, the other time I backtrack along the edge. How many such edges are there? How many red edges are there? [Student: n minus 1] The number of these red edges would be n minus 1. Why? [Student: forward tree] why it is a tree? Who said it is a tree? We are going to use a different argument for it s a tree. First why should this have n minus 1 edges? For every vertex there is one edge along which I came to that vertex and the same edge along which I backtrack from that vertex. So for every vertex there is a unique edge except for the first vertex. Since for every vertex there is a unique edge except for one, there should be n minus 1 edges. So number of red edges equals n minus 1. If I just look at the red edges, they form a connected sub graph. Why do they form a connected sub graph? Because by walking along the red edges, I could visit all the vertices. Yes, all I did was walk along the red edges. That s all I did. So by just by using the red edges, I could visit all the vertices starting from the root, from this start vertex. These red edges form a connected sub graph. (Refer Slide Time: 23:00)

7 So connected sub graphs with n minus 1 edges is a tree. Yes, we have done this before. If I have connected sub graph with only n minus 1 edges in it, it cannot have a cycle we have proved this. So it s a tree. The red edges form a tree and this tree is also called the DFS tree, the depth first search tree. Is this clear? Just as we had a breadth first search tree, a breadth first search tree was defined in terms of predecessors. Here also we can have a notion of a predecessor. What is the predecessor of this vertex? The vertex which was visited at time one because why should that be the predecessor? I came to here from there so that is an actual notion of predecessor and these edges then the same thing, same idea is getting repeated. Just as we had a breadth first search tree there, we have a depth first search tree here. But the breadth first search and the depth first search tree are completely different. What I am going to do now is to redraw this tree. I am going to keep it like this. Can you all see the picture? I am going to redraw it so that it looks like a rooted tree now. This is this vertex and let me draw it in brown. This is that and the next vertex would be there and from here I have this, so this is this vertex that I have drawn, from here I have an edge to there and I have another edge. These are all the 6 vertices. If you want, I will put down the numbers so that you can also see the correspondences. This is 0 slash 11, this is the 1 slash 10, this is 2 slash 3, this is 4 slash 9, 5 slash 6, 7 slash 8. Let me also draw the other edges of the graph. Right now I have only drawn the tree edges, the DFS tree edges. These are the edges along which we traveled. Let me also draw the other edges. How many other edges do we have? We have 4 other edges. There is one edge from here to here, there is one edge from 1/ 10 to 7/8. This is another edge, this is this edge. There is one edge from 7 8 to 0 11 this edge, there is this edge 0 11 to 5 6. Let me draw it like that. This is an undirected graph so these directions that I have shown are meaningless. It is just to signify that this is how we moved and now I can get rid of this picture. This is our graph. I have just redrawn it so that now it looks like a rooted tree and the predecessor of the node now is just the parent of that node. If I define this as the root then there is a natural parent child relationship between the nodes. The parent of this node is this and it is also the predecessor. So quite often we will talk in terms of parent child siblings and all for a DFS tree. When we say that basically means we are thinking of the starting vertex is the root of the tree and we are basically hanging the tree from there and then whatever is the parent child relationship that gets defined that s what we are working with. Let s look at more properties of depth first search. These green edges, so the brown edges are called tree edges, that s the brown edges. The green edges are called back edges and we will see why they are called back edges and why not front edges. What s back about them? Now let me think of depth first search has been done on this graph. This is the entire graph. All the edges and the vertices are here. I started from this vertex, I came down to this, I came down to this and then I looked at, this was one option available to me. But this edge was going back to a vertex which I had already visited. Yes, and so this is called a back edge, going back to a vertex which is already visited. [Hindi]

9 Why can t we have an edge from here to here? [Student: because then it would be a ancestor of this and have been visited earlier it would be] If there was an edge from here to here [Student: it has to be child of ancestor when do we backtrack before backtracking we would cover that vertex that path would have already been covered]. What is a formal way of saying this? Why should we have only edges from a vertex? Let s just put down what we have concluded so far. From a vertex we can have edges only to ancestors and such edges are called back edges. What is a back edge? So now we are ready to define what a back edge is. Anyone, what is a back edge? An edge [student: from a node to another] from a node to an ancestor. What is an ancestor? An ancestor with respect to the depth first search with respect to the DFS tree. The notion of an ancestor is coming in only because we have defined DFS tree. An edge from a node to an ancestor is called a back edge but not to [Student: but not to parent] An edge from a node to a parent is a tree edge. So we will distinguish between tree and back edges. An ancestor is not a parent let s say. Those are the back edges and these edges, the once in the red dotted here are not back edges because they are not going from a node to its ancestor. Neither is this node an ancestor of this nor is this an ancestor of this. So such edges cannot be there at all in our graph. Depth first search basically means, so after you do a depth first search you end up dividing now the set of edges into two classes tree edges and back edges and there is no other edge. [Student: we can just say that any edge] Every edge gets classified either as a tree edge or as a back edge. Let me write this down. So DFS classifies every edge as a tree or a back edge. This is similar to breadth first search means breadth first search classifies every edge as an edge going between adjacent levels or going within the same level, let s see. (Refer Slide Time: 36.49)

10 So here depth first search also does this thing for us. Clear to everyone? We are still talking about depth first search in undirected graphs. When we come to directed graphs things will change a bit, keep that in mind. How do we implement depth first search? Looks like a fairly complicated thing. Stacks or recursion let s see. What are the things we needed? We said we have to keep track of whether a vertex is visited or it s not visited. Whether what the color of a vertex is. So actually we don t even need to distinguish between grey and black. We just need to distinguish between white and non-white, whether a vertex is visited or it was not visited. That was the only thing we really needed. We are going to keep an array called visited. So what will this have? Basically it will have an entry for every vertex. For a vertex v it will have an entry let s say 0 or 1, 0 if it is not visited and 1 if it is visited. This is a zero one entry, zero means not visited. Initially all the entries of this array would be a zero. [Hindi] Suppose I wanted to do a depth first search starting from a vertex v in my graph. So now my graph is going to become more abstract. This is my graph, this is a vertex v, I want to do a depth first search from this vertex. So what am I going to do? What does depth first search involve, what is the first thing I should do? First I should mark this vertex as visited. Clearly let s say this is the very first thing I do, visited v equals one. Now I have to look at all the vertices one after the other, adjacent vertices. So let s say this had 3 adjacent vertices x, y, z. Let s put down a loop for all w adjacent to v, do something. For all vertices w, so w is just a running variable so to say which will take the value x, y or z depending upon which this is. What should I do? [Student: doffs dfs dfs w] I just do visited dfs w right away. No. [Student:] If it is not visited. If visited w [student: equal to one] equal to zero, if not of visited w then [student: dfs] just say DFS (w). [Hindi] else [student: no else how can you define] no else then what? [Student: the else w will backtrack] Backtrack. [Student: else backtrack if for all w] for all w [Hindi] [Student: not of visited of w then we backtrack visited w equal to one] Visited w equal to one [Hindi] (Refer Slide Time: 41:15). If it has now then [student: sir predecessor] backtrack [student: [Hindi]. if all w is not visited then we backtrack to the predecessor sir after we have done]. Basically [Hindi] but this takes care of everything for us, all our backtracking everything. It is not trivial to understand this part. Why it is taking care of all the things for us? [Hindi] For all [student: adjacent vertices] [Hindi] all adjacent vertices [Hindi] but to convenience yourself this is doing all of that. You know recursion is not magic right it s after all just a piece of code. [Hindi] It is particularly well suited for depth first search. You can write three line program, four line program for something we spent 30 minutes telling what the procedure is.

12 so this terminates now. This terminates means the DFS on v terminates, this whole process terminates. The claim is I would have visited all the vertices that were to be visited. From this vertex which are the vertices I can reach. If I reach a certain vertex, either I can reach it through x or through y or through z. Because after all these are the only three edges incident at this vertex. If I can reach it from x then that means it should have been visited in DFS (x). If I can reach it from y, it should have been reachable from DFS (y). If I can reach it from z, it should also have been reachable from DFS (y). Why? Because z is reachable from y. If z is reachable from y then after I had reached z, I would have continued and visited all vertices which can be reached from z. So anything that is reachable from v therefore is visited and so our DFS from v should terminate and that is exactly what is being done here. We are not done with this yet as you can imagine. I want to add my timestamps. How should I modify this procedure? [Student: starts] Suppose with each vertex I want not juts visited but I have two other arrays arrival. Let s call it a and departure let s call it d. So a of v so this is also an array and this is also an array. It is not a zero one array sorry, so this zero one was for the previous thing. If I have a vertex u, so a of u will be an integer which will tell me what time I reached vertex u. And d of u would be another integer which will tell me at what time I left vertex u. What modification should I make to this piece of code? [Student: when d of u] [Student: a of u comes when you start DFS v after visited]. So a of u equals [student: plus plus b plus whatever] time plus plus [student: and after DFS not after DFS w after] [Hindi] [student: after the for loop] [Hindi]. It s just saying stamp and increment so that the next guy doesn t get the same stamp. It could be plus plus time or time plus plus, doesn t make too much of difference. It will just change the starting. Yes, no? So and time could initially be zero [Hindi]. You can also modify this procedure to identify which edge is a tree edge and which edge is a back edge. Can you do that? [Student: if visited w] [Student: for DFS w we can mark its edge]. Suppose I also wanted this information. Every edge which is a tree edge, I want to mark the tree edge. [Student: with is equal to one then] when I am ready to launch DFS w then that means. What does that mean, what can I conclude at this point? [Student: noise] which edge? v w [student: v], the edge v w is a tree edge that I can conclude. [Hindi] I can write that statement [Hindi].

13 (Refer Slide Time: 52.48) v w is a tree edge. If you have identified what the tree edges are then its equivalent to identifying what the back edges are, anything which is not a tree edge is a back edge. I am going to stop here today. In the next class we are going to see to analyze the running time of this procedure and we are going to spend a couple of classes in applications of depth first search.

(Refer Slide Time: 06:01)

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 28 Applications of DFS Today we are going to be talking about

(Refer Slide Time: 05:25)

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering IIT Delhi Lecture 30 Applications of DFS in Directed Graphs Today we are going to look at more applications

(Refer Slide Time: 01.26)

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture # 22 Why Sorting? Today we are going to be looking at sorting.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 18 Tries Today we are going to be talking about another data

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 20 Priority Queues Today we are going to look at the priority

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 04 Lecture - 01 Merge Sort (Refer

Combinatorics Prof. Dr. L. Sunil Chandran Department of Computer Science and Automation Indian Institute of Science, Bangalore

Combinatorics Prof. Dr. L. Sunil Chandran Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 5 Elementary concepts and basic counting principles So, welcome

(Refer Slide Time: 1:43)

(Refer Slide Time: 1:43) Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology, Madras Lecture - 27 Pattern Detector So, we talked about Moore

Programming and Data Structure

Programming and Data Structure Dr. P.P.Chakraborty Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture # 09 Problem Decomposition by Recursion - II We will

(Refer Slide Time: 1:27)

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 1 Introduction to Data Structures and Algorithms Welcome to data

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

CS2 Algorithms and Data Structures Note 10 Depth-First Search and Topological Sorting In this lecture, we will analyse the running time of DFS and discuss a few applications. 10.1 A recursive implementation

High Performance Computing Prof. Matthew Jacob Department of Computer Science and Automation Indian Institute of Science, Bangalore

High Performance Computing Prof. Matthew Jacob Department of Computer Science and Automation Indian Institute of Science, Bangalore Module No # 09 Lecture No # 40 This is lecture forty of the course on

Artificial Intelligence Prof. Deepak Khemani Department of Computer Science and Engineering Indian Institute of Technology, Madras

Artificial Intelligence Prof. Deepak Khemani Department of Computer Science and Engineering Indian Institute of Technology, Madras (Refer Slide Time: 00:17) Lecture No - 10 Hill Climbing So, we were looking

Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Module No. # 10 Lecture No. # 16 Machine-Independent Optimizations Welcome to the

MITOCW watch?v=zm5mw5nkzjg

MITOCW watch?v=zm5mw5nkzjg The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

Project and Production Management Prof. Arun Kanda Department of Mechanical Engineering Indian Institute of Technology, Delhi

Project and Production Management Prof. Arun Kanda Department of Mechanical Engineering Indian Institute of Technology, Delhi Lecture - 8 Consistency and Redundancy in Project networks In today s lecture

(Refer Slide Time: 00:02:00)

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 18 Polyfill - Scan Conversion of a Polygon Today we will discuss the concepts

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Module 07 Lecture - 38 Divide and Conquer: Closest Pair of Points We now look at another divide and conquer algorithm,

(Refer Slide Time 6:48)

Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 8 Karnaugh Map Minimization using Maxterms We have been taking about

Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we

Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we have to talk about the way in which we represent the

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 15 Branching : IF ELSE Statement We are looking

CS 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

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion Today s video will talk about an important concept in computer science which is

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

01.433/33 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/2/1.1 Introduction In this lecture we ll talk about a useful abstraction, priority queues, which are

Depth-First Search Depth-first search (DFS) is another way to traverse the graph.

Depth-First Search Depth-first search (DFS) is another way to traverse the graph. Motivating example: In a video game, you are searching for a path from a point in a maze to the exit. The maze can be modeled

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 31 Static Members Welcome to Module 16 of Programming in C++.

There are many other applications like constructing the expression tree from the postorder expression. I leave you with an idea as how to do it.

Programming, Data Structures and Algorithms Prof. Hema Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 49 Module 09 Other applications: expression tree

Programming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras

Programming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 13 Merging using Queue ADT and Queue types In the

Programming in C ++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C ++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 27 Copy Constructor and Copy Assignment Operator (Contd.) Welcome

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras Lecture 28 Chinese Postman Problem In this lecture we study the Chinese postman

(Refer Slide Time: 0:19)

Theory of Computation. Professor somenath Biswas. Department of Computer Science & Engineering. Indian Institute of Technology, Kanpur. Lecture-15. Decision Problems for Regular Languages. (Refer Slide

Figure 4.1: The evolution of a rooted tree.

106 CHAPTER 4. INDUCTION, RECURSION AND RECURRENCES 4.6 Rooted Trees 4.6.1 The idea of a rooted tree We talked about how a tree diagram helps us visualize merge sort or other divide and conquer algorithms.

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

Information Security II Prof. Kamakoti Department of Computer Science and Engineering Indian Institute of Technology, Madras

Information Security II Prof. Kamakoti Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 30 Task Switch recap - Week 6 (Refer Slide Time: 00:09) So welcome back

Scribes: 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

MAL 376: Graph Algorithms I Semester Lecture 1: July 24

MAL 376: Graph Algorithms I Semester 2014-2015 Lecture 1: July 24 Course Coordinator: Prof. B. S. Panda Scribes: Raghuvansh, Himanshu, Mohit, Abhishek Disclaimer: These notes have not been subjected to

BST Deletion. First, we need to find the value which is easy because we can just use the method we developed for BST_Search.

BST Deletion Deleting a value from a Binary Search Tree is a bit more complicated than inserting a value, but we will deal with the steps one at a time. First, we need to find the value which is easy because

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?

(Refer Slide Time 5:19)

Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology, Madras Lecture - 7 Logic Minimization using Karnaugh Maps In the last lecture we introduced

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Lecture 04 Software Test Automation: JUnit as an example

6.001 Notes: Section 31.1

6.001 Notes: Section 31.1 Slide 31.1.1 In previous lectures we have seen a number of important themes, which relate to designing code for complex systems. One was the idea of proof by induction, meaning

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Trees : Part Section. () (2) Preorder, Postorder and Levelorder Traversals Definition: A tree is a connected graph with no cycles Consequences: Between any two vertices, there is exactly one unique path

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

(Refer Slide Time 01:41 min)

Programming and Data Structure Dr. P.P.Chakraborty Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture # 03 C Programming - II We shall continue our study of

Database Management System Prof. D. Janakiram Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Database Management System Prof. D. Janakiram Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. # 20 Concurrency Control Part -1 Foundations for concurrency

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 18 Switch Statement (Contd.) And Introduction to

(Refer Slide Time: 1:40)

Computer Architecture Prof. Anshul Kumar Department of Computer Science and Engineering, Indian Institute of Technology, Delhi Lecture - 3 Instruction Set Architecture - 1 Today I will start discussion

Database management system Prof. D. Janakiram Department of Computer Science and Engineering Indian Institute of Technology, Madras

Database management system Prof. D. Janakiram Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 25 Basic 2-phase & 3-phase Commit protocol In the last lecture,

TIE 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

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

Graphs. The ultimate data structure. graphs 1

Graphs The ultimate data structure graphs 1 Definition of graph Non-linear data structure consisting of nodes & links between them (like trees in this sense) Unlike trees, graph nodes may be completely

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Computer Science 0 Data Structures Siena College Fall 08 Topic Notes: Trees We ve spent a lot of time looking at a variety of structures where there is a natural linear ordering of the elements in arrays,

Continuing with whatever we saw in the previous lectures, we are going to discuss or continue to discuss the hardwired logic design.

Computer Organization Part I Prof. S. Raman Department of Computer Science & Engineering Indian Institute of Technology Lecture 10 Controller Design: Micro programmed and hard wired (contd) Continuing

(Refer Slide Time: 00:01:30)

Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology, Madras Lecture - 32 Design using Programmable Logic Devices (Refer Slide Time: 00:01:30)

Animations involving numbers

136 Chapter 8 Animations involving numbers 8.1 Model and view The examples of Chapter 6 all compute the next picture in the animation from the previous picture. This turns out to be a rather restrictive

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture - 04 Introduction to Programming Language Concepts

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling Welcome to the lectures on computer graphics. We have

6.001 Notes: Section 15.1

6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define

CSI 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

(Re)Introduction to Graphs and Some Algorithms

(Re)Introduction to Graphs and Some Algorithms Graph Terminology (I) A graph is defined by a set of vertices V and a set of edges E. The edge set must work over the defined vertices in the vertex set.

Binary Trees

Binary Trees 4-7-2005 Opening Discussion What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment? What is a Tree? You are all familiar with what

Graphs. The ultimate data structure. graphs 1

Graphs The ultimate data structure graphs 1 Definition of graph Non-linear data structure consisting of nodes & links between them (like trees in this sense) Unlike trees, graph nodes may be completely

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5 [talking head] This lecture we study theory design and implementation. Programmers have two roles to play here. In one role, they

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Module 02 Lecture - 45 Memoization

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Module 02 Lecture - 45 Memoization Let us continue our discussion of inductive definitions. (Refer Slide Time: 00:05)

Lecture 3: Graphs and flows

Chapter 3 Lecture 3: Graphs and flows Graphs: a useful combinatorial structure. Definitions: graph, directed and undirected graph, edge as ordered pair, path, cycle, connected graph, strongly connected

(Refer Slide Time: 00:51)

Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute Technology, Madras Module 10 E Lecture 24 Content Example: factorial

(Refer Slide Time: 00:18)

Programming, Data Structures and Algorithms Prof. N. S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 11 Lecture 58 Problem: single source shortest

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

CME 305: Discrete Mathematics and Algorithms Instructor: Professor Aaron Sidford (sidford@stanford.edu) January 11, 2018 Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1 In this lecture

Week - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program.

Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 03 Euclid's Algorithm

14.1 Encoding for different models of computation

Lecture 14 Decidable languages In the previous lecture we discussed some examples of encoding schemes, through which various objects can be represented by strings over a given alphabet. We will begin this

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 08 Constants and Inline Functions Welcome to module 6 of Programming

CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14

CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14 1 Depth first search 1.1 The Algorithm Besides breadth first search, which we saw in class in relation to Dijkstra s algorithm, there is one

W4231: Analysis of Algorithms

W4231: Analysis of Algorithms 10/21/1999 Definitions for graphs Breadth First Search and Depth First Search Topological Sort. Graphs AgraphG is given by a set of vertices V and a set of edges E. Normally

Week - 03 Lecture - 18 Recursion. For the last lecture of this week, we will look at recursive functions. (Refer Slide Time: 00:05)

Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 03 Lecture - 18 Recursion For the

UNIT 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,

Order from Chaos. University of Nebraska-Lincoln Discrete Mathematics Seminar

Order from Chaos University of Nebraska-Lincoln Discrete Mathematics Seminar Austin Mohr Department of Mathematics Nebraska Wesleyan University February 8, 20 The (, )-Puzzle Start by drawing six dots

CS 4349 Lecture October 18th, 2017

CS 4349 Lecture October 18th, 2017 Main topics for #lecture include #minimum_spanning_trees. Prelude Homework 6 due today. Homework 7 due Wednesday, October 25th. Homework 7 has one normal homework problem.

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

1 Review 1 Something I did not emphasize enough last time is that during the execution of depth-firstsearch, we construct depth-first-search trees. One graph may have multiple depth-firstsearch trees,

Shadows in the graphics pipeline Steve Marschner Cornell University CS 569 Spring 2008, 19 February There are a number of visual cues that help let the viewer know about the 3D relationships between objects

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

MITOCW Lecture 10A [MUSIC PLAYING] PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between all these high-level languages like Lisp and the query

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 9 Normal Forms

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras Lecture - 9 Normal Forms In the last class we have seen some consequences and some equivalences,

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras Lecture - 35 Quadratic Programming In this lecture, we continue our discussion on

Graph Theory. Chapter 4.

Graph Theory. Chapter 4. Wandering. Here is an algorithm, due to Tarry, that constructs a walk in a connected graph, starting at any vertex v 0, traversing each edge exactly once in each direction, and

Kuratowski Notes , Fall 2005, Prof. Peter Shor Revised Fall 2007

Kuratowski Notes 8.30, Fall 005, Prof. Peter Shor Revised Fall 007 Unfortunately, the OCW notes on Kuratowski s theorem seem to have several things substantially wrong with the proof, and the notes from

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems Problems, Hints, and Solutions Chapter 1 Searching and Sorting Problems 1 1.1 Array with One Missing 1.1.1 Problem Let A = A[1],..., A[n] be an array

Graph 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

Intro. Scheme Basics. scm> 5 5. scm>

Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

Computer Algorithms-2 Prof. Dr. Shashank K. Mehta Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

Computer Algorithms-2 Prof. Dr. Shashank K. Mehta Department of Computer Science and Engineering Indian Institute of Technology, Kanpur Lecture - 6 Minimum Spanning Tree Hello. Today, we will discuss an

6.001 Notes: Section 4.1

6.001 Notes: Section 4.1 Slide 4.1.1 In this lecture, we are going to take a careful look at the kinds of procedures we can build. We will first go back to look very carefully at the substitution model,

Elementary 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

1 5,9,2,7,6,10,4,3,8,1 The first number (5) is automatically the first number of the sorted list

Algorithms One of the more challenging aspects of Computer Science are algorithms. An algorithm is a plan that solves a problem. When assembling a bicycle based on the included instructions, in this case,

TIE 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

(Refer Slide Time: 01:25)

Computer Architecture Prof. Anshul Kumar Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture - 32 Memory Hierarchy: Virtual Memory (contd.) We have discussed virtual

Computer Architecture Prof. Mainak Chaudhuri Department of Computer Science & Engineering Indian Institute of Technology, Kanpur

Computer Architecture Prof. Mainak Chaudhuri Department of Computer Science & Engineering Indian Institute of Technology, Kanpur Lecture - 7 Case study with MIPS-I So, we were discussing (Refer Time: 00:20),

Announcements. 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

A simple problem that has a solution that is far deeper than expected!

The Water, Gas, Electricity Problem A simple problem that has a solution that is far deeper than expected! Consider the diagram below of three houses and three utilities: water, gas, and electricity. Each

5 R1 The one green in the same place so either of these could be green.

Page: 1 of 20 1 R1 Now. Maybe what we should do is write out the cases that work. We wrote out one of them really very clearly here. [R1 takes out some papers.] Right? You did the one here um where you

Chapter 11: Graphs and Trees. March 23, 2008

Chapter 11: Graphs and Trees March 23, 2008 Outline 1 11.1 Graphs: An Introduction 2 11.2 Paths and Circuits 3 11.3 Matrix Representations of Graphs 4 11.5 Trees Graphs: Basic Definitions Informally, a