 In this lecture we will be discussing on the transitive closure of a relation suppose R is a relation on a on a set a then we call the transitive closure of R another relation which we denote by R plus such that R is transitive R contains sorry R plus is transitive R is contained in R plus and R plus is the smallest transitive relation containing R so there are three points to be remembered R plus must be transitive second point to remember is R is a subset of R plus and the third point to remember is that if T is a transitive relation on a such that R is a subset of T which in turn is a subset of R plus then T equal to R plus if for R plus the above three conditions hold then R plus is said to be the transitive closure of R now our problem here is to find out a way of computing R plus from R we start by checking the powers of R that is R composed by itself so we consider R and then we define R square which is also written as R composition R as a R square B if and only if there exists a one belonging to a such that a related to a one and a one related to B in this way we can extend the this idea to R raise to the power some k so we define R raise to the power k which is essentially R composition and so on R composition and composition R and this whole thing is k times all right as a R raise to the power k B if and only if there exists a sequence of elements of a a 1 up to a k-1 all inside a such that a R a 1 a 1 R a 2 so on up to a k-1 R a here it is B so the last element here is a k-1 R B all right now the result that we are going to prove here is R plus that is a transitive closure R plus that is a transitive closure of R is same as R union R square union and so on up to R but we do not stop here we keep on going so I just keep on taking powers of R and add in the union and the totality that we will we get is R plus that is what we claim here so I can in a compact notation write this is equal to k equal to 1 to infinity R raise to the power k now the question is that where is the proof and that is exactly that we are going to do now we will write for the time being R prime as the union k equal to 1 to infinity R raise to the power k and we will prove that R prime is indeed the transitive closure of R so to do that first of all we have to prove that R prime is a transitive relation one suppose a R prime B and B R prime C for some a B C belonging to A this means that there exists i, j belonging to the set of positive integers such that a R raise to the power i B and B R raise to the power j C this is because R prime is union of our all R raise to the power case and therefore if a is R prime B then of course there is some element i for which a is R raise to the power i B and similarly for B B and C now by definition of the power of relations what we have here is that there exists a 1 up to a i – 1 and B 1 up to B j – 1 all belonging to a such that all right we have a chain starting from a a related to a 1 a 1 related to a 2 and we proceed in this way to a i – 1 related to B but what happens here that the chain does not stop here we can pick up from B which is related to B 1 and B 1 related to B 2 and so on and ultimately we come to B j – 1 related to C and therefore if we combine this whole chain then we will get a related to R raise to the power i plus j C but this means that a union k equal to 1 to infinity R raise to the power k C which in turn means that a R dash C thus at least we have proved that R prime is transitive the second point that we have to prove is somewhat easy because we have to prove that R is a subset of R prime and that is true because after all R prime is union of R and other powers of R therefore it is easy to check that R is a subset of R prime so I will write here that it is easy to check next we move on to prove probably the most difficult part of the proof that is R prime is the smallest transitive relation containing R we write it as the point 3 now let us think that how to prove this fact so I would like to prove that R prime is the smallest transitive relation containing R that means I have to prove that there is no relation containing R which is transitive and properly contained in R prime so let us suppose that we have a relation which is which let us denote by T and which is sandwiched in between R and R prime so here suppose T is a transitive relation such that R is a subset of T which in turn is a subset of R prime what we will prove is that if such a thing happens then T is forced to be equal to R prime and that proves that there can be no proper subset of R prime which contains R and transitive at the same time now to do this we have to prove that T equal to R prime and that means a set theoretically T is a subset of R prime and R prime is also a subset of T now this part of the chain already tells us that T is a subset of R prime so there is nothing to prove so we have to prove the other way round that R prime is a subset of T to do that we have to start with an element of R prime now suppose we have an element of R prime we denote it by a b well technically we can write a b belongs to R prime which essentially means that a is R prime b right and this means remembering that R prime is nothing but k starting from 1 to infinity R raise to the power k all right so since a b belongs to R prime that therefore a b has to be in some R raise to the power i for some positive i so therefore I can write a R raise to the power i b where i belongs to z to the power plus that is positive integer and since a R to the power a is R to the power i b we will have i – 1 elements from a such that we can build a chain of relations as we have seen before so this implies that there exists a 1 a 2 so on up to a i – 1 all belonging to a such that a R a 1 a 1 R a 2 a proceed like this and then at end we have a i – 1 R b now in the next step we realize that by our assumption we have R a subset of T since R is a subset of T all right since R is a subset of T if we have two elements related through R then they are also related to T so therefore we can just change it to a T a 1 a 1 T a 2 and we proceed like this and ultimately we will have a i – 1 T b now we know something more about T we know that T is transitive so T is transitive why T is transitive because we have assumed it to be so so since T is transitive what we realize is that we can kind of collapse this chain here to just a T b why because if you consider these two points in the chain since T is transitive we can write a T a 2 the next element will be a 2 T a 3 and if well there is a next element to this then it will be a 3 T a 4 and ultimately we will arrive at a i – 1 T b but then I can collapse it again we can combine these two to write a T a 3 and proceed and ultimately get a i – 1 T b this is all because T is transitive and therefore at the end we will end up with a T b but what does it mean this means that the pair a, b is an element of T and therefore we now check the whole chain of arguments we started with assuming that the ordered pair a, b belongs to R' and we end up by deriving that the ordered pair a, b belongs to T this means that R' is a subset of T now we check that we have already observed that T is a subset of R' and that is by the definition and we have derived that R' is a subset of T all by using the property that T contains R T is transitive and T is inside R' therefore we can write that T is equal to R' and this proves that R' is the transitive closure of R now as we have started by writing transitive closure of a relation by R to the power plus therefore we can write in symbols that R' is equal to R to the power plus so that is to say again the same thing that R' is the transitive closure of R now see that this whole thing becomes simpler if our underlying set is a finite set we need to simplify this whole scenario because as we have seen that okay if you give me a relation R then R plus is a union of a infinite sequence of elements namely R union R square union and so on some maybe R to the power k and so on which we are writing as union k from 1 to infinity R to the power k well okay theoretically we have proved this but it is it is not necessarily true that we will be able to the computation in general because we have a we have to compute union of infinitely many elements therefore we need something simpler and we would like to have something simpler for at least finite cases and indeed we have a much simpler result when the set a contains only n element which we will write as a1 a2 up to an okay so by putting a within two vertical lines we denote the number of elements of a and in this case it is n what we will show first is that suppose two elements in a let us denote them by a and b are related by some R to the power i of b then we will as we have seen before have a chain of relations so to say connecting a to b so we will have elements like a1 up to a I will rather change the definition change the notation over here because I am writing the elements of a as a1 a2 and all these things so what I will be doing instead is that I will say that suppose there we when we have got a R raise to the power i b then we have some b1 dot dot dot bi-1 belonging to a such that a R b1 b1 R b2 up to bi-1 R b here we have to remember few things that this bi is has nothing to do with the ordering a i's and I may be much larger than n so and another thing that we have to note over here that I have not told that bi's are distinct they may repeat so I have essentially a sequence of elements b1 b2 up to bi-1 where there may be repetitions and we may call it the sequence of internal the points or the sequence of interior points so I will be calling them sequence of interior points a an element from the sequence let us say BJ will be coin will be called interior point this whole chain starting from a and one after another a sequence of alternatively R and some bi this whole chain is called a path from a to b path from a to b in we can call it in a with respect to the relation R so I can write it I will just say it is a path from a to b if we assume that we know a and we know R now there is a there is an important parameter associated to this path which is called the length of this path is simply I why I because we see that this one we have got one then two and like this so we will have I number of places where we are using the relation if we have I-1 interior points please note again that these interior points need not be distinct if we think in terms of digraph this is very intuitive what we have here essentially a point a and a point b in a or in the set of vertices when we are looking at this whole setup as as digraphs then we have a and b and then we have some let us say b1 and a relation a related to b1 means that we have a directed path then we again have something else b2 then we have b3 then we have let us say b4 but this is where what I am coming to that this this interior points need not be distinct so from before we may go back again to b2 but then this b2 is also b5 and from b5 we will go to b6 and similarly we will proceed till we get to b from bi-1 and the number of links that we have used is essentially the length of the path now what we will notice here that if along the path a vertex or an element or a point of a is repeated like in this portion b2 to b5 we can essentially cut this loop out and in the process reduce the length of the path we can do this more systematically like here please see that I am first writing the path this is a and this is a or b1 then a are sorry let me remove this right and then we have b1 or b2 let us suppose we come to some bl-1 or bl and then bl or bl-1 again we proceed then at some point we get another element let us say call it bk-1 or bk and then we have bk or bk-1 and we proceed again till we reach the end of the path which is bi-1 or and the last one is b we have a path like this and suppose bl is equal to bk l is strictly less than k then as we have seen in the diagram but in this case more formally we can write a path from a to b as a starting from b1 and so on till we reach bl-1 are and here instead of bl I can just write bk the reason is that bl and bk are same and then continue in the same sequence to get bk bk-1 and so on up to bi-1 are b right we get this now of course this is a path from a to b of length i we have obtained another path from a to b of length strictly less than i because l is strictly less than k and well what we have done is that we have cut out two two equal in interior points just merge them and then gone on with our path now we can keep on doing this process and at the end we will have a path which does not have any repeated interior points that means a path such that all interior points are distinct so continuing in this way we can arrive a path from a to b such that all interior points distinct now let us go back to the set on which we are considering the relation this set has got only n elements a1 up to an and so if we take any two points in a if they are connected by a path we can we know that we have already seen that we can and we can always do that connect a and b through a path where interior points are distinct but these interior points are going to come from the set a itself and nowhere else therefore if a and b are different and both are in a the number of possible interior points that we can get is n-2 so any path can be reduced to a path containing n-2 distinct elements of a if a and b are not equal therefore the length of the path will be n-1 suppose a and b are equal then we are left with n-1 elements of a and therefore at most we can have a path with n-1 distinct interior points in fact it will be a loop starting from a point of a and going through the points of capital A and go back to the original point so the length of this path will be n so in this case if we have two elements if they are at all related by some r raise to the power i they are related by some r raise to the power j where j is strictly less than or equal to n and greater than equal to 1 therefore r plus which is union k equal to 1 to infinity r raise to the power k is simply the union of a finite set of relations this now we can do computation with this suppose we have to find out the matrix corresponding to the relation r plus then it will be the matrix corresponding to the relation r union r square union and so on up to r raise to the power n which in turn is the matrix MR or the matrix MR square and so on up to the matrix MR raise to the power n which in turn is the matrix MR or the matrix MR square the matrix MR raise to the power n where this MR raise to the power i will mean MR MR and so on up to MR i times where this particular operation is the operation of binary matrices that we have discussed before which corresponds to the composition of the relations this we have covered in previous lecture so we have this situation now we can start checking an example yeah so let us take a set and a relation so now my set a is a b c d and e and the relation r is given by a a a b b c c d c e and d e our problem is to find r plus in the first step we construct MR now if we check carefully we will see that MR is 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 and the last row is all 0 like this this we have to find out by finding the matrix corresponding to r that we have discussed in a previous lecture now we keep on considering the powers of this relation where MR square is nothing but MR multiplied by MR with a special rule that we have discussed before and that will give us 1 1 1 0 0 0 0 0 0 0 0 0 0 1 and 0 0 0 0 0 0 along with 0 0 0 0 0 so this so I will request you to check all the calculations and I will tell you one way of doing this when we are trying to compute MR square which is MR product MR what we can do is that we can just take matrix multiplication as such and then at each entry we have to check that whether the entry is 0 or non-zero if the entry is 0 keep it as 0 if the entry is non-zero change it to 1 and then you will get a matrix like this and if you try the same rule with MR cube we will get 1 1 1 1 1 1 0 0 0 0 1 and rest of the rows all 0s and in exactly the same way multiplying MR three times four times by using the same product we will get MR to the power 4 which is 1 1 1 1 1 and rest of the rows are 0s all right and then lastly we have MR to the power 5 which is again same as MR to the power 4 and then our job will be to take the union of all these relations and in the matrix form it will be MR plus is equal to MR or MR square or MR cube or MR to the power 4 or MR to the power 5 and this if we check carefully is 1 1 1 1 1 0 0 1 1 1 then 0 0 0 1 1 0 0 0 0 1 and the last row is 0 0 up to 0 all 0s so this is the matrix corresponding to MR plus then we have to construct the relation corresponding to these matrix for that again we will use whatever we have studied before we remember that in all these cases we have not tampered with the ordering of a therefore these columns are labeled by ABCDE and the rows are labeled by ABCDE therefore we see that the entry corresponding to AA gives 1 so it is in the relation so AA is in the relation AB is also in the relation AC is also in the relation AD is in the relation AE is in the relation we come to the second row where we have B we see that BA the corresponding entry is 0 so it is not in the relation BB is not in relation but BC is in the relation so we will write B, C then we write B, D we write B, E then we come to the third row CA is not in the relation CB is not in the relation CC is not in the relation but it starts from CD CD and CE are in the relation so we write CD CE and lastly we see that DE is in the relation and there is no other element in the relation so ultimately we have R plus as a set and set it is a subset of a Cartesian product a now the problem with this technique is that we have to do lot of work as we have seen that each time we have to keep on multiplying MR with whatever we have obtained before what we are doing is probably little less complicated than matrix multiplication but it is ultimately ultimately the same in terms of the number of number of elements that we have to compare in the worst possible case therefore we would like to know whether we can do it in a faster way and indeed there is an algorithm called Worshaw's algorithm which does it in a much more faster and convenient way this algorithm we will study in the next lecture for today this is the end thank you