[00:00:02] So, let us start. In the last lecture, we were discussing about the heap and heap sort. Okay. And we try to also form heap from set of elements. The only property that we have to maintain, that is, either we have to choose a mean heap or max heap configuration. And when I am saying that it is mean heap, so root will hold the minimum element, root with minimum element. [00:00:31] And if, if I am saying max heap, then root will always hold the maximum element. Okay. [00:00:42] And this is valid for entire tree. So, root will be greater than or equal to left or right [00:00:49] chain. So, or equal to is also here. So, heap allowed the duplicate entries as well. Okay. [00:00:55] Then we have discussed that upon subsequently deleting the root, upon subsequently deleting [00:01:03] the root, what we may store, if we may store these value, just a minute, if we store this [00:01:12] value, okay, then we will form a either ascending or descending order depending what type of [00:01:19] we are using and the elements are already sorted. So, upon deletion there is one more [00:01:32] thing that happens that is heap phi that restores, that restores the heap property. [00:01:49] What basically we do, basically we remove the root and replace with the last element and replace with [00:01:57] with last element. And of course, if it is last element, then there will be a violation [00:02:04] in the property. So, the hippie phi is the operation of restoring that property. So, [00:02:11] we have already discussed on this complexities as equivalent to that of merge, quick and [00:02:16] other sorting algorithm. Then we discuss about the first, so basically it is the multiple [00:02:21] trees that are there in place. Now, this is the last topic in the tree, that is red black tree. [00:02:29] And if I comment on the insertion and deletion, so they are little bit complicated. And deletion [00:02:39] of the arbitrary is assumed to be the one of the toughest topic in the entire algorithm. [00:02:43] So, what I will do, I will let you know the properties that are there in the RB tree and [00:02:53] basically RB tree is a binary search tree with a balancing mechanism. Balancing mechanism is what? [00:03:02] Balancing is via the color that we will see what is RB tree and how it balances. [00:03:08] So, likewise in BST, the balanced version was AVL. [00:03:15] Similarly, there is one more version of BST whose balanced version is called arbitrary. [00:03:21] So, there we were performing different rotations and all. [00:03:25] And here we have to maintain certain set of properties. [00:03:31] So, let us discuss one thing. [00:03:37] So, we have discussed binary search tree. [00:03:47] So, for balancing, there is one mechanism that already we have discussed AVL tree with [00:03:57] a balance factor of minus 1, 0 or 1. [00:04:00] Here we will have discussed RB tree, that is of course, it is a binary search tree where [00:04:07] it uses color and black height to balance the tree. [00:04:16] So, we will see how it balances. [00:04:18] but basically the thing in the BST is balancing with the help of colors and number of black node [00:04:32] in each path. That we will see. So here black height or number of black node in each path. [00:04:47] Now, why I am saying black node? [00:04:48] Because if you know its name is what? [00:04:50] R, B, tree. [00:04:54] So, R implies red. [00:04:56] B implies black. [00:04:58] Red, black tree or R, B tree. [00:05:00] So, as the name indicates, red, black. [00:05:04] So, there will be an extra field in each node. [00:05:07] There will be an extra field in each node that is specify the color is either. [00:05:12] let us specify the color that should that could be red or black that could be red or black okay [00:05:20] so binary search tree balancing can be achieved with the help of avl or rb tree and in case of [00:05:31] rb tree as the name indicated is a red black tree the node color could be either red or black okay [00:05:37] then we will consider so what will happen let's say i construct a tree so let's say this color is [00:05:44] black. This may be red, this may be black. So, there are some property how this color [00:05:52] positioning will be happening. So, there will be an extra field that stores the color value. [00:05:58] If you remember in case of AVL, there was an extra field that is called balance factor. [00:06:04] And through balance factor, we know whether the tree is holding the property of AVL or not. [00:06:10] Similarly, in AVL tree, we will, in RB tree, we will check out the colors, okay, and its specific organization. [00:06:18] So, RB tree is one of the many search tree scheme that are balanced. [00:06:23] In order to guarantee the basic dynamic set operation take, we go off log off and time in worst case. [00:06:40] One extra bit of storage per node is color, okay, which can be either red or black. [00:06:54] this is important information in arbitrary there will be an extra bit extra bit that indicate [00:07:01] color is red or black okay next this line is very important what it say by constraining [00:07:08] the node color any simple path important but any simple path from root to the leaf in arbitrary [00:07:16] ensure that no such path is more than twice as long as any other okay so what this indicates that [00:07:24] if I have one path from root to leaf, that is 2. So, all the other path in the tree [00:07:31] can never be greater than 2 or 2 times 2, that is 4. This is the thing here. What it says, [00:07:42] any simple path from root to leaf ensures that no such path is more than twice as long as [00:07:50] any other. So, if let us say length of a path is 4, so you will never find a path that is [00:08:01] greater than 8 or so. Each node is now having what? What are the attributes of each node? [00:08:09] You see, color, key value, the information that it stores, left child, right child and [00:08:15] information regarding parent if if it is a root node then parent is what null if it is leaf node [00:08:22] then left is null and right is null okay and key will be the info part whatever the information it [00:08:30] was a story and of course color will be always there either a leaf root anything okay so these [00:08:40] are the five property that is very famous and you should be aware of these are the five property [00:08:49] what it say every node is either red or black that is clear because that is clear from the name [00:08:57] okay and this rb tree is not a m way tree b tree or b plus tree it is basically a binary search [00:09:10] tree okay so this is a binary search tree then second property that is very important that is [00:09:24] root is black the root is black okay third one every leaf nil is black so if i say null node [00:09:34] okay that is always assumed to be black fourth one is if node is red if any node i am considering [00:09:42] is red both the children are black that is very important property its violation is [00:09:47] change the property or this violation occurs when we are inserting new node. [00:09:57] Okay. And this is another important what to say. For each node, all the simple froth from node to [00:10:05] descendant leaf contains same number of black nodes. So, in any path you follow from root to [00:10:10] leaf, you will find same number of black node, same number of black node. And this also concludes [00:10:22] that the the previous property any simple path to one so if in any path the number of black node is [00:10:27] same so no path can be two times to any of the other path okay so let us see this tree i hope [00:10:37] the colors are visible this is black this is red okay so root is always black in color one property [00:10:45] property to fulfill every node is either red or black so you say here it is black here it is red [00:10:52] black red black black and all the nils are black in color all the nils are black in color okay so [00:11:01] all the nils are black in color color of node is either red or black that the property is fulfilling [00:11:07] the root is black in color so of course it is black in color this is red in color okay now the [00:11:16] The third property is if a node is red, if a node is red, so both the children are black. [00:11:26] So if you see here, they are black. If a node is red, both the children are black. If a [00:11:33] node is red, both the children are black because we know that nil is also black in color. So [00:11:39] this property is also fulfilling if a node is red, both the children are black. Node [00:11:44] is red, both the children are black, node is red, both the children are black, okay. [00:11:51] So this property is also holding, now the important and the last property is each node, [00:11:56] all the simple path from one node to descendant leaf contain the same number of black nodes. [00:12:01] So let us check. [00:12:02] So this is root and this is one path, so black node 1, black node 2, we reach here, so number [00:12:08] of black node is 2. [00:12:09] check another path one two this path this one node this two node so same we are reaching it [00:12:19] then another path one then sixteen is two two node in this path one two one two in this path [00:12:30] one black two one black two one black two so in every path what we find two black [00:12:41] nodes. In some of the books, they are considering nil as also. So of course, if there is a nil, [00:12:46] then we can say that 3 node, but fairly if we ignore the nil thing, then we can easily say that [00:12:52] the number of black node in each path is only 2. So all these 5 properties are fulfilling here. [00:13:03] Okay, and thus we can conclude that this is a red-black tree, okay. [00:13:10] So I hope these properties are clear, okay. [00:13:14] And what I will do, I will share the PPT of insertion and deletion as well, but I am not [00:13:19] going to ask because it is very much tricky and it will consume most of all time. [00:13:24] Those who are interested can check out that, okay. [00:13:27] Now let us start the another unit that is graph, okay. [00:13:31] So in graph we will try to cover up. [00:13:33] as fast as we can and then we will see other things as well. Okay. Just stopping for a while [00:13:39] and then, okay. Sorry for the interruption. Okay. So, let us start the new unit that is [00:19:04] graph and its application. Okay. So, up till this, we have covered the [00:19:11] algorithms that are primarily for the trees. Okay. So, we have covered trees and [00:19:24] while discussing the tree or if you go with the definition wise. So, tree are the [00:19:32] acyclic, acyclic variant, okay. So, there should not be any cycle or loop. There will be no cycle [00:19:45] or loop or loop, no cycle or loop in the graph, okay. So, every time we find a tree like this [00:19:54] one okay no close boundary you can say no close boundary no close no close boundary no cycle no [00:20:05] loop okay so that are there in the tree and when i talk about graph so graph says graph can [00:20:19] can be acyclic can be cyclic there may be loop there may be close boundary [00:20:30] There may be closed boundary, there may be cycle. So, everything is allowed or what we [00:20:40] can say that if tree is represented by T and graph is represented by G, so T is a subset [00:20:47] of G. So, there is a famous question, what is difference between tree and graph data [00:20:53] structure? So, tree allowed only acyclic nature. Acyclic nature means that there should not [00:21:01] be any closed boundary, loop, self loop, anything, but graph do allow it, okay. So, that is [00:21:06] a very, very basic difference and most of the types it is being asked, okay. So, let [00:21:13] us see a graph or multi-graph. Sometimes it is also referred as multi-graph, okay. Why [00:21:21] it is multi-graph? Because a subset of graph is also a graph, like tree, a subset of graph [00:21:34] is also graph. So, a graph G consists of two things that is important. So, it is G V comma [00:21:51] E set of vertices and set of edges, set of vertices and set of edges, set of vertices [00:22:06] and set of edges. Graph comprises set of vertices and set of edges. So, a set of v of element called [00:22:31] nodes or pointer. And a set of edge is the, you can say, linkage between. So, the v, a set of v [00:22:54] of element called nodes or somewhere it is called pointer or vertices. So, primarily we will call [00:22:59] it as vertices. And a set E of edges such that each edge E in capital E. So, all the [00:23:06] edges will be part of the set, edge set, all the vertices will be part of vertex set. [00:23:12] Okay, is a unique unordered pair u comma v denoted by E edges in between two vertices [00:23:21] u and v. So, basically we have two vertices v1 and v2, in between there will be an edge e1. [00:23:35] So, what we can see e1 is ordered pair of v1, v2. So, edge is represented by the two extreme ends [00:23:42] vertices. So, most of the cases we will not write edge e, we will write what? v1, v2 as edge, [00:23:50] v2, v3 could be another edge and so on. Now, the degree of node u, [00:24:00] first thing, suppose e is u comma v, e is the edge in between vertex u comma v. [00:24:07] So, the node u and v are called as the end point of e. The node u and v are called as the end point [00:24:14] of e, that is the edge. Edge has two points. So, v1 is end point and v2 is also end point. [00:24:21] and u and v are said to be the adjacent node in the network. So, they are of course adjacent. [00:24:25] Adjacent means that this is closer, directly linked to the v1 and v2 are directly linked. [00:24:31] Similarly u1 and v, u and v maybe. So, this is u, this is v. So, u v edge e. So, they are called as [00:24:39] the adjacent. Now, there is one more term that is called degree. So, degree of any node u, [00:24:46] So, degree will be of course associated with the vertex, is the number of edges containing [00:24:53] u, the number of edges that are linked or connected to the u, that is called as the [00:24:59] degree. [00:25:00] So, what is the degree? [00:25:01] If I had one more slide, so for example, if I form a graph, graph may have closed boundary, [00:25:19] that is the important thing. [00:25:20] So, let us say this is 1, V1, V2, V3, V4, V5. [00:25:28] So, now let us check degree of V1 is what? [00:25:32] Two edges, 1, 2, degree of V2. [00:25:38] Where 1, 2, 3, degree of V3 is what? [00:25:45] 1, 2, degree of V4 is what? [00:25:50] 1 to degree of v5 is what? 3. So, simple degree is estimated. Next, if degree of u is 0, if degree [00:26:09] of any of the node is 0, it does not belong the NEH or u is called as the isolated node. [00:26:15] So, for example, if I make a hair of v6, it is not connected, so degree of v6 is 0. [00:26:24] So it is disconnected component, it is disconnected node or we can say disconnected vertex. [00:26:40] So then also further we will also talk about the in degree and out degree, we will talk [00:26:45] about directed graph. [00:26:46] So there will be a specific direction. [00:26:48] So what is directed graph? [00:26:50] graph is nothing but this is undirected, there is no specific direction, this is undirected [00:27:01] graph and if I draw a graph like this, so there will be a specified direction. [00:27:14] This is directed graph, where there is a specific direction of movement. There is a [00:27:36] specific direction of movement, then that is called as the directed graph. So in directed [00:27:42] graph degree is estimated because there may be edge incident thing and going outside. [00:27:48] So, there we called as the in degree and out degree. So, we will discuss this just in after [00:27:55] one two slide what is in degree and what is out degree and how we can determine the source and [00:28:01] sink by only viewing the in degree and out degree. So, there is another concept that is called as the [00:28:13] path. So path of length n from u to v is defined as sequence of n plus node. So for example, [00:28:21] if I create a path, so here if it is u, here it is v and in between v1, v2, v3. So it is saying [00:28:32] that path is what? u v1, v1 v2, v2 v3, v3 v. These are the, so this is called as the path that is [00:28:42] here it is written v0, v1, v2, v3, vn. So, path is what? The number of ages and we know [00:28:50] that age is represented by ordered pair of vertices. So, all the ages are represented [00:28:55] with the help of two vertices. Therefore, n plus 1 vertex will be required to represent [00:29:00] a path of length n. A graph G, next thing is connected graph. That is important. This [00:29:10] is path and now we are talking about connected. So, a graph G is said to be connected if there [00:29:23] is a path between any two of its node. So, if you see the previous example, this is connected [00:29:30] graph, all the nodes are connected. And if I consider V6 and then it is a disconnected [00:29:39] graph because there is no edge of movement. So, the graph is said to be connected if there [00:29:45] is the path between any two pair of itself. Any two pairs of nodes have a path then it is a part [00:29:52] of graph, it is a connected graph. Or in other terms if you be more specific or more specified [00:30:02] what we can say that a graph G is connected if and only if there is a simple path between any two [00:30:10] nodes in the graph. There is a simple part between any two nodes in the graph. [00:30:18] Now, so one, two, three terms we are seeing. So, graph G is represented by V and E. [00:30:40] V is set of vertices and E is set of edges. Then we talk about edge E is ordered pair [00:31:02] of u comma v. This v and this v are different. This is a big V representing the set and this [00:31:12] This is a single entity, then u and v are endpoints, then we talk about path is ordered [00:31:30] pair vertices. [00:31:41] Then one discuss about connected, connected means that there should be edge, there should [00:31:53] to be edge in any two pair of vertices. Another one is called as the complete graph. Another [00:32:18] one is complete graph. So a graph is said to be complete if every node u in v is adjacent [00:32:24] to each other. What this means that there is an edge between all pair of vertices. So, [00:32:46] this is strength. So, what we can say all the nodes are connected to each other. And [00:32:53] number of edges in this case is n into n minus 1 by 2. So, this is the number of edges that [00:33:08] this graph will possess. So, if you can easily for this one, I can calculate. So, what it [00:33:17] will be? Three vertices, 3 into 2 by 2. So, that is three edges. If I draw a graph like [00:33:23] this this is also a complete graph 4a so 4h n is 4 so 4 into 3 by 2 so that is 6 so if you can see [00:33:36] 6 edges are there another another example we could take that is pentagon so i hope it is wrong now [00:34:13] number of if number of vertices is 5 same up apply the formula edges that will be 5 into [00:34:21] 4 by 2 that is 10 edges are required. And important part is that degree of each vertex, [00:34:31] degree of each vertex in complete graph is what? n minus 1. So, if you see here number of [00:34:39] vertices are 5. So, if you see a degree 1, 2, 3, 4, here degree is 1, 2, 3, 4, here degree is 1, [00:34:47] 2, 3, 4, here is 1, 2, 3, 4. So this is important for complete graph. This is important for complete [00:34:59] graph. So now a connected graph t without any cycle, this already we have discussed, a connected [00:35:10] graph t without any cycle is called tree graph or free tree or simple tree. But we have studied [00:35:18] in the previous lectures that was trig. And P is a finite tree with m nodes and number of ages [00:35:32] will be m minus 1. So, for example, if I draw this, so number of ages is how much? 2 and number [00:35:40] of vertices is 3. So, there is a direct formula for the tree. That is, if node is n, then total [00:35:45] number of ages will be n minus 1. If it is greater than n minus 1, then of course, there will be a [00:35:51] a loop or a closed boundary. There will be a loop or a closed boundary. So, this is looping [00:35:58] and this is multi-edge graph that you can check. This is also a graph, but this is a [00:36:05] kind of tree because there is no loop or boundary. And this is a weighted graph. Weighted graph [00:36:11] means there is a assigned weight to all the edges. So, therefore, it is called as the [00:36:19] weighted graph okay so uh let me take the queries uh parambit then then we will go ahead for the [00:36:29] directed graph discussion if anyone else otherwise because these are the very generic [00:36:35] thing that i am discussing no query then i will start discussing this directed graph [00:36:41] sort of go ahead please good morning sir good morning yes sir basically i have a question on [00:36:51] like uh red black tree uh yeah the the one introduced in the red black tree is uh balanced [00:36:58] binary search tree right so yeah is also a balanced binary search tree so basically we know that [00:37:03] uh in binary search tree that due to the skewness problem we introduced avl so yeah so what's the [00:37:10] reason that we introduced red black tree because uh although we have avl tree no so what has [00:37:15] happening when this bst was skewed so some persons started working towards the avl tree [00:37:24] and some person is starting toward the rb tree so this is the two solution of a single problem [00:37:29] okay and one more thing this tree rb tree are more stabilized one as compared to avl later on but [00:37:37] of course these are the single problem two solution so basically sir we can say there [00:37:42] is no advantage over one another if we choose directly advantage over now but but but if you [00:37:50] if you have to choose whether i go with avl or rb so you have to go with rb so what's the reason [00:37:56] that we have to go with rb instead of abl because here in place of directly estimating the what [00:38:04] balance factor for balance factor you need to calculate the black left height and right height [00:38:10] always but in case of arbitrary what we have to do just maintain the color okay okay so we are [00:38:15] not getting the difference so basically so it is like uh calculating the balance factor is [00:38:22] way complicated than maintaining the color maintaining the color portion yeah yeah [00:38:27] okay so answer the one more question related to tree and graph uh sir is there anything such [00:38:33] called like directed tree because till now we have seen the tree as only the undirected because tree [00:38:40] is also a subset of that is possible that is possible but the thing is that now there is [00:38:45] exactly one age okay so because what i am doing i can go this if the direction is specified [00:38:52] and if it is joked or blocked and one one important thing is that uh very rare you can go from root [00:39:00] to the leaf but from the leaf to the root there is very less possibility of movement so [00:39:05] of course it is allowed if you draw a tree if you draw a structure like this this is also a [00:39:11] directed tree okay but in most of the cases we assume it is bi-directional so this arrow is does [00:39:17] not mean that single and it is means that we can move from down to up and up to down [00:39:23] so basically yeah yeah basically it is so it is wider yes please basically mystery is undirected [00:39:32] graph yeah yeah no not it is undirected graph it is a cyclic graph so you can also point the [00:39:39] direction in the tree that is up to you okay so we can never say it is undirected we can say it [00:39:45] is a cyclic graph okay so basically we can say that either we can make connection between two [00:39:54] nodes in the tree by having two edges like one for in direction and one for out direction yeah [00:39:59] yeah yeah that is possible right that is that is why in some book it is written the the undirected [00:40:04] graph are said as bi-directional graph okay okay so that's all my question thank you so there are [00:40:20] no more questions yeah yeah thank you thank you so now the next graph is directed graph okay so [00:40:31] all the algorithms okay all the algorithms that we will see will cover will utilize [00:40:52] directed graph that is very much important okay so undirected graph you will see very rare okay [00:40:58] undirected graph, you will see where as last person was asking undirected tree. So, the [00:41:04] undirected graph you will rarely see, you will rarely see. So, what is directed graph? [00:41:15] A directed graph is also called as digraph or simple graph is the same as multi graph expect [00:41:22] that the edge e in the g is assigned a direction. Or in other word, each edge in identified with an [00:41:30] order pair u comma v in d and okay so ordered pair means u should appear first then v should appear [00:41:40] that is important we cannot change the order and here it was in undirected graph the possibility [00:41:47] of changing the order was there v u or u v both are allowed okay so just wait for one minute one [00:42:04] or two minutes, then I will start. Just opening the slide, just read everyone. So, [00:49:39] directed graph is also called as digraph. So, suppose we have G, a directed graph with [00:49:54] with directed at e comma v, then just a minute, I hope my mic is on here. So, the e is also [00:50:06] called as the arc. So, e begin at u and end at v, this is important, e begin at u and [00:50:15] end at v. So, that is directed graph, u is the origin, because there is a direction, [00:50:24] is direction. So, u is the origin or initial point of E and v is the destination or terminal [00:50:36] point of E. V and v is the destination or the terminal point. And other terms in somewhere [00:50:48] it is also referred u is predecessor and v is successor u is predecessor and v is successor [00:51:02] okay so u is adjacent to v and v is adjacent to u so these are the some terminologies [00:51:10] that we will see when we are discussing the algorithms so adjacent [00:51:15] predecessor and successor, initial point, destination or terminal point. And one more [00:51:26] thing that is origin or initial point and destination or terminal point. And U is called [00:51:49] as the source and this is also called as the sink, source and sink. [00:51:55] Now as I have discussed, there will be the concept of in degree and out degree, because [00:52:03] here we are referring the directed graph, here we are referring the directed graph. [00:52:23] So adding one more slide, in degree and out degree. [00:52:27] So what is in degree, another term is out degree, if I make a graph and specify the [00:52:45] directions. Let us say this is e1, e2, e3, v4 and this is v5. So, if you see here, there are [00:53:21] directions. So, in degree is what? Number of incidenting edge. So, in degree of V1 is 0, [00:53:41] n degree of v2 is what? 2. n degree of v3 is what? v3 if you see 1. n degree of v4 is what? 1. [00:53:56] n degree of v5 is what? 1. Because one edge is only incidenting. Just a minute I am doing. [00:54:26] so in degrees basically just just a minute there is some issue just a minute so [00:56:29] we were discussing about the in degree and out degree i hope in degree is clear again i am [00:56:35] redrawing it new graph i am just proposing okay so this is v1 v2 v3 v4 v5 v6 v7 okay [00:57:07] so in degree is number of edges incidenting in degree i am just writing the name of what is this [00:57:12] v1 v2 v3 v4 v5 v6 v7 and out degree is number of outgoing edges okay v1 incidenting edge 0 [00:57:33] v2 incidenting edge 1 v3 incidenting edge 2 v4 incidenting edge 1 v5 1 v6 number of incidenting [00:57:42] edge 0 and v7 number of incidenting edge 2 now v1 outgoing 2 v1 v2 outgoing 1 v3 outgoing 0 [00:57:55] v4 outgoing 1 v5 outgoing 1 v6 out degree 0 sorry v6 out degree is 2 v7 [00:58:06] out degree is what? 0. So, that is an another concept. If in degree is 0 and out degree is [00:58:18] positive, then it is called as the source. So, v1 is a source. Similarly, v6 is a source. [00:58:28] When in degree is positive and out degree is 0, then it is called as the sink. [00:58:33] So, there are two source and two sink in this graph and this is a directed graph. So, we [00:58:42] are discussing about in degree as well as the out degree. So, here it is written out [00:58:58] degree of a node u in g is written as out degree u is the number of edges beginning [00:59:03] at u. Similarly, in degree is u written as in degree u is the number of edges ending [00:59:09] at u. A node is called as the source if out degree is positive and in degree 0. So, that [00:59:18] already we have seen. Out degree positive, in degree 0 source. A node is called sink [00:59:24] or end point if it is out degree 0 but positive in degree. So, the notation of path, simple [00:59:35] path cycle carry over from the undirected graph to the directed graph. The notations [00:59:40] of path, simple path cycle, except what? That the direction of each edge in the path must be [00:59:47] agree with the direction of the path cycle. So, if I say there is a path from u to v and there are [00:59:52] v1, v2, v3, so it should be directed. So, u to v, v1, v1 to v2, v2 to v3, v3 to v. Then only it [01:00:03] will be applicable. Otherwise, there will be no path. So, next point is reachability point. [01:00:15] node V is said to be reachable from node U if there is a directed path from U to V. So, [01:00:38] if I draw like this, U to V, so I can say that V is reachable from U, V is reachable [01:00:50] from u, but vice versa is not true, but vice versa is not true. [01:01:03] And there is also concept connected or strongly connected, if there each pair u and v in the [01:01:09] node g, there is a path from u to v and there is also path from v to u. So, maybe possible [01:01:14] this is not the direct path. So, if I draw a node like this, so u to v we have, now here [01:01:22] is x so v to x and v to x to v so we have both the path u to v we can go and from v to u if you want [01:01:30] then i can choose this path okay so if that exists then that is called as the connected or strongly [01:01:36] connected graph okay now there is another concept very simple con you can say unilaterally connected [01:01:45] means that connected in either way okay if the any pair u and v in the graph there exists a path [01:01:52] from u to v or a path from v to x and we can call it is unilaterally connected and if we call it [01:01:57] strongly connected if there is path in both the direction okay now if you see this example okay [01:02:08] that will provide you number of answers in one go so here are vertices are a b c d okay now i am [01:02:44] talking about, this is edge E1, this is edge E2, these are the parallel edges. [01:02:52] These are the parallel edges. This class is a little bit theoretical oriented because [01:02:59] we are understanding the terms. So, next class onwards, we will see the details. [01:03:06] So, edge E2 and E3 are the parallel edges. Here it is written because they are starting and [01:03:13] terminating on the same node. So what is the parallelage? They start and terminate on same [01:03:28] vertices. Now then E7 is a loop. If you see here it is starting here and ending here as well. [01:03:58] This is called loop or we can say that E7 is a self loop, self loop because starting and end is [01:04:07] same. And this, these loops and other aspects are not allowed there in the tree. [01:04:13] Now, see the sequence B, C, D, C, B, A. So, let us check D, C, but here direction is what? In this [01:04:25] direction, C, B is not possible. So, it is not a path because what we can do? D, C is fine, [01:04:32] but C, B is not fine because we cannot go in that direction. Then D, B, A if you see D, [01:04:38] B, A is a path. G is unilaterally connected. So, that is of course, there is in between [01:04:46] two edges, there is a path. So, that we can say that is unilaterally connected. Unilaterally [01:04:50] means that in any, any way it is connected. Either, either U to V or V to V. If it is [01:04:55] connected, then it is called unilaterally. In degree of D is 1, C in D. D in degree is [01:05:01] what? 1. Out degree of D is 2. Out degree of D is 2. Fine. C is sink. C is sink. If you see C, [01:05:09] all the edges are incidenting. So, C is sink. And no node in graph is source, of course, because [01:05:15] there is none of the node that is having positive out degree and 0 in degree. So, [01:05:24] So that is just a brief, there are other terminologies as well, rooted tree, so designated [01:05:33] node. [01:05:34] So similarly, we will have, so as the class proceed, if I encountered any term, then I [01:05:42] will let you know. [01:05:44] So now, as we have seen the link representation and sequential representation in the tree, [01:05:50] so there is also there in case of graph. [01:05:54] So, the sequential representation here in graph is called as the adjacency matrix. [01:06:05] So, why it is called matrix because, just wait, so if I have a graph, I am just connecting, [01:06:37] make this now randomly putting some direction and this is a b c d e okay these are the vertices okay [01:06:54] now what is adjacency matrix it say that if adjacency means what if something it adjacent [01:07:01] then I will declare. So, I just make a matrix A, B, C, D, E. And here also A, B, C, D, E. [01:07:23] So, is A is adjacent to A? So, if you see the definition, what to say? If one, if V i is [01:07:31] adjacent to V j, that is if there is an edge between V i and V j. So, A is adjacent to A, [01:07:42] I consider it 0 because it is same vertex. So, in this case, let us put the diagonal to 0. [01:07:50] In some way, it is also 1. Now, is there is any edge from A to B? A to B, yes. A to C? No. So, [01:07:58] it is 0. A to D, any edge? No. A to E, any edge? No. Because it is directional. Now, B. B to A, [01:08:07] 0. B to C, yes. B to D, 0. Edge, I am talking about direct edge, not path. Okay. Then A, B to E, [01:08:18] 0. Now coming to the C. C to A, yes. C to B, no. C to D, yes. C to E, 0. Now coming to the D part. [01:08:32] So, D to A, 0, D to B, 0, D to C, 0, D to E, 0. Now, E, E to A, yes, E to B, 0, E to C, yes, E to D, yes. [01:08:50] So, this is nothing but this is adjacency. If there is a direct edge, then we will declare it as 1, otherwise we will put it 0. [01:08:58] So, this is sequential representation of a graph in a form of matrix. [01:09:02] So, very good. [01:09:03] So, if we have a matrix of ABC cross ABC, so from this we can reconstruct back the graph. [01:09:11] So, this is adjacency matrix, but the problem is that let us say your graph is very sparse. [01:09:17] There are few ways between pair of vertices, then maximum storage will be wasted here as [01:09:23] well. [01:09:24] how to resolve that that is done via another thing that is called as adjacency list and that is the [01:09:31] link representation of the graph just a minute okay so okay i will take the queries let me finish [01:13:01] this so this is adjacency representation or sequential representation of the graph so here [01:13:08] it is also written if v is adjacent to vj that is there is an edge between vi and vj okay so [01:13:14] So, yeah, Parambir, so enable mic for those who are raising hand, then we will see the link representation of the graph. [01:13:30] Mubala, please go ahead. [01:13:34] Hi, sir. Good morning. [01:13:36] Good morning. [01:13:36] Sir, the question I have is in the previous graph where we have categorized the graph as unilateral. [01:13:45] So, if we just change the edge of B and C, the reverse, then can we say that it has fully connected? [01:13:54] fully connected. If not strongly connected, fully connected means that there is a possibility [01:14:03] of reachability from each pair of vertices. But why not strongly connected? So in strongly [01:14:12] connected there will be a direct edge between all the pairs. Between all the pairs. So that [01:14:20] means i can only go to like if i go to u to v then i could only go from go back from v to u [01:14:28] via directed edge and not like any other by by not in support of any other things right yeah okay [01:14:35] got it thank you sort of going please hello sir yes sir i have a bit of confusion in a strongly [01:14:47] connected and unilaterally collected so can you just uh re-explain this with a bit of example [01:14:54] okay so uh if i reach from u to v unilaterally connected but if there is a provision of v to u [01:15:02] okay actually strongly connected is uh you can say that both way movement can be possible [01:15:08] both way means that via third edge or anything uh yeah the last question uh so just sorry so uh [01:15:14] if there is a possibility of moment in the both the direction for all pair of vertices. [01:15:18] Okay, so last one was asking strongly connected. So, that is direct edge is only possible in [01:15:24] undirected graph. Here if there is no direct possibility. So, if we can reach from one [01:15:28] vertex or if I am drawing this adjacency matrix, so I am getting all ones except the diagonal. [01:15:34] And that is a strongly connected. And unilectically means that there is, there is [01:15:40] u v two nodes are there so there is at least one path i can go from u to v or from v to u not both [01:15:48] way okay so it means that if there is uh like uh if two nodes are if every nodes in a graph are [01:15:55] adjacent to one another then we can say it is strongly connected yeah yeah or if there is a [01:16:01] possibility of moving from each node in both the direction right so so basically if two nodes are [01:16:10] adjacent it means that there will be a edge from like if u is adjacent to v and v is adjacent to u [01:16:16] then there will be a like edge from u to v and v to u as well direct sorry edge yeah so if i see [01:16:26] like this u to v okay so this is unilaterally if but there is a provision that we can reach to u [01:16:37] then then then then it will be so sir okay so there there is one question like you're like [01:16:45] v is adjacent to you this statement holds here but can we say in this graph that uh you is [01:16:53] adjacent to v no no so we cannot say you adjacent to v but we can say that you can be connected via [01:16:58] the v or we can reachable so okay so last question was also there so now just there is a concept is [01:17:05] called reachability. If both the vertices are reachable from one and another, if all [01:17:10] the pair of vertices are reachable from one and another, then we can say that it is strongly [01:17:14] connected. So this is a reachability concept. Or the last one, those who were asking may [01:17:21] be confused. So just a single thing, reachability. If reachable, strongly connected. If it is [01:17:27] not reachable or reachable in one direction, then unilaterally connected. [01:17:30] okay answer uh for the uh like if two nodes had to be adjacent to one another then there would be [01:17:38] there have to be a direct edge between two of them two direction so a to b and there will be [01:17:43] two a two pathways should be there okay so basically this question arises because in one [01:17:48] of the slides it was like uh both are uh like you told that it is adjacent but there is only [01:17:54] apart from you to be so this was bit okay okay fine no so that's why now i i prefer questions [01:18:00] so others doubt will be clear okay thank you sir uh there are no more questions yeah yeah thank you [01:18:11] so uh let me think about the next topic that is adjacency list okay but these are interrelated [01:18:18] that's why i'm covering so maybe class may extend for another five minutes i hope you people will [01:18:23] not bother. So adjacency matrix, so here it is written, if you see here, the diagonal is all 0. [01:18:38] And here if you see from x to w, there is no direct path, x to w, there is no direct path, [01:18:47] x to z, there is no direct path, x to w, there is a direct path, so it is 1. Now y to x, y to x, [01:18:55] there is direct path y to z no direct yes there is one direct path and y to w no direct path so [01:19:02] it is zero so this is adjacency representation of the graph but there is a problem with this okay [01:19:10] so if if i had a matrix of this kind all zeros only one or two one then all this space is wasted [01:19:21] okay so how to minimize the wastage if your graph is strongly corrected or densely populated then [01:19:28] we can prefer the adjacency matrix representation but if it is sparse if number of ones are very low [01:19:38] then we will choose another representation that is called as the link representation okay so basic [01:19:43] idea of link representation is what so i just make an array of one two three and put all the nodes [01:19:49] that are connected. So, from 0, from 1 there is 0 connected and 2 connected. From 2, 0 is connected [01:20:00] and from 0, no one is connected. So, accordingly this graph is formed. But if we try to do for a [01:20:07] connected graph or a strongly connected graph, then in each list we will have what? [01:20:11] Multiple nodes. So, that is not recommended. When your graph is sparse, [01:20:16] then only we are choosing the adjacency list and otherwise we are choosing the adjacency matrices. [01:20:23] So, here is an example, adjacency matrix A, B, C, D, E. So, from A to A, 0, A to B, 1, A to C, 1, [01:20:39] A to D, 0, A to E, 1. That already we have built. Now, if we try to develop adjacency list, [01:20:46] So, from a what are the path? B, C, E. So, B, C, E and null is the stopping point. From [01:20:53] b what are the path? C, null is a stopping point. From c what are the path? D, null is [01:20:59] the stopping point. From d what are the path? E, null is the stopping point. From e what [01:21:03] is the other? C, null is the stopping point. So, if you see how many spaces required here. [01:21:13] So required space is 5 x 5, 25 and here the space required is what, this is 5, 6, 7, [01:21:22] 8, 9, 10, 11, 12. [01:21:25] So in 12 space I can represent because if you see the matrix here the number of zeros [01:21:29] are very high. [01:21:30] So in 12 address spaces or 12 places I can store the entire graph rather than using 25. [01:21:39] So this is how adjacency matrix and let us say if your matrix is dense. [01:21:44] we will require more space. So adjacency list is preferred when your graph is sparse [01:21:53] and adjacency matrix is preferred when your graph is dense. Dense means that there will be multiple [01:21:58] edges among this. So these are the some basic terminologies that we have witnessed in the graph. [01:22:04] Now we will talk about the searching in graph, insertion in graph, deletion in graph and [01:22:08] traversal in graph. So these are the four basic operations in any data structure. [01:22:12] So, searching already we have did in case of trees, in search and deletion we have seen [01:22:16] number of trees. [01:22:17] So, traversal there are two famous algorithm, depth first search and breadth first search. [01:22:23] So, that we will see and I hope most of you are aware of. [01:22:28] Then we will see the minimum spanning tree problem, Kruskal-Prim algorithm. [01:22:33] As the lecture proceed and as per our availability, we will cover up the topic that we can. [01:22:42] these two algorithms, DFS and BFS, we will see very briefly in the next class. Although what I [01:22:47] will do, I will share this PPT, just go through it. So, if you got the idea, because everything [01:22:52] is very clearly written and I have shown all the possibilities of this one. And if this cover up [01:23:00] in short duration, then what we will do, we will start the minimum spanning tree problem in the [01:23:06] upcoming lecture okay so that's all for today and i hope tomorrow is holiday on account of chad [01:23:14] puja who will will see you on the next saturday okay and thank you uh parambi for assisting me [01:23:22] doing this class if anyone has any doubt yeah please there are two questions enable the mic [01:23:30] dukesh please go ahead morning sir on the previous slide [01:23:40] if you could scroll down to previous slide where you were explaining the path [01:23:45] this one sir is missing a doubt as i say a path a to b b to c and c to d [01:23:52] we don't have any path between c to e right yes but if you see here a to b b to c c to e [01:24:06] there is no path between c to e yes yes yes but we we are we have represented here a to b here [01:24:14] this one one sir c to e is not a path e to c is e to c is the path so here from here we are seeing [01:24:26] e to c right sir neechi neechi jo apne adjacency list me jo display kara hai e to b e to c is here [01:24:35] e to c okay this this you are talking about na yeah so this is not a connected path this is just [01:24:43] a representation ki what are the nevers of a it is not this that not means that there is a path [01:24:48] between b to c c to e it is just the representation of showing that these are the adjacent vertices [01:24:53] of the a okay okay so there is not a representation so if you are confused so don't apply the [01:25:01] directional just put a single sign okay get it thank you jayanth go ahead please jayanth i have [01:25:26] unmuted you please go ahead i think jayanth is not able to communicate sir there are no more [01:25:38] questions okay okay thank you thank you thank you yeah i'm closing thank you sir [01:25:42] and happy chhat puja same to happy chhat puja to everyone