 So, far in this course you have already got exposed to the notion formal notion of algorithm and then the respective problems so called decidable problems. And in contrast we have also from theoretical point of view you have already understood how to observe a problem is undecidable and you have understood some of the undecidable problems. So, in the real world problems the problems which are you know which can be handled through algorithms that we are interested in and the notion of algorithm as a Turing machine as a through a Turing machine model that we have realized and observed some of the problems which are of importance. Now, in your algorithms course you would have you know concentrated on the topics like you know the main concepts like designing algorithm and understanding its complexity complexity of an algorithm. So, complexity you will be you would have looked into various aspects particularly if you look for time complexity space complexity and within the time complexity various classes etcetera. Now, here what do we do we have already understood for to some extent that theoretically for what kind of problems you will be designing algorithms and some of the examples that we have identified. And we have also understood through this course that what are the problems that you cannot have an algorithm. So, so called undecidable problems that we have discussed. Now, towards end of this course now what we will look for is you know some glimpses of complexity theory that means whatever the algorithms that you have designed may be here as a through Turing machine model some deciders that you have designed. Now, we will understand what is the complexity of that particular design that you have done. In particular we will look for time complexity that means in case of algorithms the way that you have done in your algorithms course you will be counting the number of computational steps and you are reporting with respect to the input parameter if say for example n is the input parameter. So, depending on what are the data set that you are using and some parameter n and with respect to that you are reporting the complexity may be some T n as complexity of that particular algorithm. Now, here we will go in a systematic way I will introduce how we actually report the complexity of a particular algorithm here Turing machine and what is the notion and the related some glimpses of complexity theory that we will discuss in this course. Here first I introduce the notion of like how we count the number of steps in Turing machine. So, let me give this definition formally let m be a Turing machine that m be a Turing machine and configurations be configurations. Now, for a number natural number T we say C yields C dash in T steps. So, from this term itself you know you can guess what would be the definition, but let me present formally here we say C yields C dash in T steps that is what I am going to denoted by this notation is somewhat close to the ones which we have already discussed. So, this in T number of steps you have to get C dash from C. So, naturally the definition is if there is a computation you know the computation we write like this. So, there is a computation the star of exactly T steps. So, when we have discussed computations you know this C gives C dash infinitely many steps that is what is known as computation and this computation that relation that with respect to star reflexive transducer of one step relation we have discussed. Now, this C should give C dash in exactly T number of steps in which case on that relation symbol I will write what is the number of steps there. So, now we formally look at that this particular thing. So, between two configurations for various natural numbers. So, depending on the number of steps that it is taking to yield one to another that we put on that particular relational symbol. So, that is what is happening here you have certain configurations in between say C 1, C 2, C 3 and so on C T minus 1 such that. So, that means there exist some configuration such that C gives C 1 in one step then C 2 and so on C T minus 1 and then you get C dash from that. So, you have exactly T number of steps because the first step and the second step here and in T minus 1 steps you have reached here and one more step to get C dash. So, exactly in T steps if you can get then we say we denoted like this and C yield C dash in T steps. So, we are counting the number of steps that a Turing mission takes to yield one configuration from another. So, this notion we will use now to introduce the following let T from natural numbers to natural numbers a function be a function take a function and a language or some alphabet which is not containing black. So, we are writing sigma naught a language. So, take these things now a Turing mission say m equal to q sigma delta q naught with that sigma naught is contained in sigma a Turing mission decides L in time t. So, what we are defining when do we say a Turing mission m decides L in time t. So, if the following holds what is that whenever x is in L in that language then if you start the mission with x as input. So, that is the initial configuration in T number of steps if it should halt by saying s because this is the language. So, this T for some T this number is less than equal to T. So, the input parameter is essentially we have taken the length of the input string and whenever this string is not in the language the Turing mission has to say no within the time bound steps. So, it will say no if it is not in the language. So, this is the output, but the number of steps it is taking for some T less than equal to T mod x. So, that means you look at here you are given a function T and a language we say a Turing mission m of course, the language you should be able to feed the strings of L you should be able to feed to the Turing mission. Therefore, we are taking the condition that sigma naught is contained in sigma this particular condition and now we say this Turing mission decides L in time t if the following condition holds what is that condition if x is in the language the decider has to say s you know that and if x is not in the language you know that decider has to say no for that particular string. Now, it is not only that we are putting a time restriction on it with respect to the function T given to us what type of time restriction. So, whatever the input that you are giving x the length of x is the input parameter if you call that as number say n, n length input if you are giving the number of steps it is taking to say s or no whatever depending on the depending on whether it is in the language or not it should take it should take within T of n steps. So, this is the condition that we are putting and accordingly we say that this T within this time we say L is decidable in time this. So, we will give that definition also formally we say L is decidable in time T, T is a function from natural numbers to natural numbers if there is a Turing mission there is a Turing mission that decides L in time T. We have already defined when do we say a Turing mission decides a language in time T where T is a function from natural numbers to natural numbers that we have already mentioned. Now, if you take an arbitrary language and time T we say that L is decidable in time T if there is a Turing mission the way that we have mentioned if there is a Turing mission which decides L in time T. So, this is now I will let me give one notation here and a notation is I use this time T if you are given a time function T the time T I mean those languages which are decidable in time T. So, time T we mean. So, you collect all those languages which are decidable in time T that means for each such language you should have a Turing mission and we should decide that particular language in time T the given time function T. So, time T is that now let me give some examples a very simple example let me consider say if you take L to be set of all those strings say over a b for convenience let me consider like this such that x has an a the symbol you know this is a regular language it is very easy to construct a a a decider for this. Let me consider this particular decider say what do I do first I will take a left move I hope you are following this input notation that we have already mentioned in the definition. So, you take an input say a 1 a 2 a n on the tape and this is how we are starting and we keep cross checking. So, how I will design here you take a left move and cross check whether this particular symbol is a if it is a you are happy you continue further and you have to say s if it is not a then you can you can cross check keep going to left and that is how that is how you can you would have designed a Turing mission a decider to cross check that in the beginning say for example, if it is empty string which is not having a. So, that means in the beginning itself you will have blank. So, in which case what do you do you simply take a right move. So, and print no because here there is no a suppose in the beginning if you have some b's you can erase that simply if you have b and then take a left move. So, keep doing this if you are having b's only b's then what will happen through this particular branch if all these are b's it will you will simply erase this and so on till a a 1 that a 1 is also b then you encounter blank then you take a right move and print no and take a right move and halt in the required format that you would have decider like this. If you have a at some point in between then we have to print s for this. So, anyway this also we will erase then take a left move and thereafter whatever that you get whether a or b because you have got at least one a and therefore, you will keep continue to erase the remaining symbols and when you get blank finally, then you take a right move here you print s and take a right move. So, this is a very quick decider that you would have designed and it is easy to consider. Now, let us look at this decider how much time it is taking to decide this language. Now, we have mentioned that each transition will be counted as one step each transition will be counted as one step. Now, let us look at the transitions here although we have come we have given a Turing mission which is composition of some primitive machines. Now, here each machine how many primitive steps that it has we can easily understand and count the number of steps number of transitions look at in the first step I am taking one left move that means, here you are taking one move that means, one transition here in the beginning if it is blank. So, you are cross taking then you are taking a right move printing n and going taking a right move that means, in this branch essentially it is taking here one step here one step. So, let me write. So, here this is one step and when I take this branch it is taking one plus one plus one three steps essentially it is taking as for right move one step printing n that is one transition in the Turing mission and taking right step. So, there are three now here if it is if you are going to this branch here you are having one step and you are connecting back to this. So, here you have a loop and in every step here you are printing a blank symbol fine. Now, when you go to go through this branch here again you have one step printing step and here moving step. So, here printing step and here moving step. So, that is here one step here and one step here I am just putting the count and you have a loop here and then when you proceed to this branch then again here you have one plus one plus one steps. So, these are the primitive steps in a Turing mission that you have. Now, how to report this number because wherever you have the loop now you look at in this particular suppose if you look at the tape what you are doing from here you are coming to this particular position in this cell. So, you are taking one left move and then you are erasing it whatever it is whether it is A or B. So, in this particular cell whether it is A or B whatever it is if you look at the scheme what the way that we have designed in this particular cell you are simply erasing. So, that means one left moves mean step and one erasing step that you have. So, here let me write one step you have here and then you are taking one left move and whatever it is you are erasing here and so on. So, that means what is happening here you are taking a left move and printing something that is erasing essentially. So, taking a left move erasing that means for each of this you know till this you have two n steps that you can quickly see by the time you reach from here to here you know you have to make n number of moves and you know n number of printing steps that means 2 n number of moving and printing steps. So, you can say 2 n moving and printing steps. So, in fact n number of moving steps n number of printing steps till this point and then you take one more move left move here you have encountered blank that is what you are reading. So, at this position you are taking only one so plus one and then you take a right move and appropriately you will print either s or no depending on whether you have a or not. So, that printing step is one printing. So, you take a right move take a right move and then print one. So, this is for left move this is for right move this is for printing either s or no whatever that you print and then take a right move. So, how many steps total that you have that is 2 n plus 4 steps. Now, if you take a time function t from natural numbers to natural numbers given by t of n is equal to 2 n plus 1 that is a 2 n plus 4 then you see this time function within this time function you know the language L whatever is given here. So, let me call it as L a for the time being. So, L a is decidable L a is decidable in time t a as mentioned here because we have identified a Turing machine which is a decider which is deciding this language and the time it is taking is 2 n plus 4 steps on any input string. If the input is having a it will halt by printing s if the input is not having a then it will halt by printing no, but the total number of steps it takes is 2 n plus 4. So, this particular language is decidable in 2 n plus 4 steps. Now, let me consider this example you know this is very we are very familiar with this a power n b power n such that n greater than equal to 0. If you take this language you know this is a context free language we have designed a decider for this I hope and now let me consider a decider for this and see how much time that that decider is taking. Look I have constructed a decider if you sit you can also construct you would have constructed by now. What is the logic I am using here is if you take a n b n let me assume say for example, a string which is in the required form in the language. So, this is where I am starting the logic what I am using is I will take a left move if I am encountering b I will make it blank and go till this end and I will make it I will come to write and match whether there is a I will make it blank. But one thing I have to remember that once I erase the tape when I have to heart I have to heart with this kind of information either s or no I have to heart like this where s has to be printed in the second cell in this cell. But once if I arise if I am in between then I will not know how many number of blank cells are here. So, I have a possibility of hanging. So, this kind of you know techniques and all those things that we have already discussed earlier. So, in the first place what I will do when I reach to this particular left end I will print a special symbol. So, say for example, dollar I will print here and then when I am when I have to heart at the end of the story if I am in between somewhere middle I will go till end that means till I encounter dollar then appropriately I can handle. So, this technique I will use. So, I will design accordingly. So, what I will do? So, some trivial cases that you can check say for example, in the beginning itself suppose if you are encountering this that means if it is empty string is given as input. So, you know the blank cell and in the second blank cell you are given this tape is given like this. So, that particular thing you can handle. So, if you have blank in the beginning if you take a left move take a right move print y r because n equal to 0 a power and b power and power. In the beginning if you encounter a I am taking this branch I am arising the entire tape and then printing no. So, that is what is this particular branch and if I am starting with b then what are the mechanism I have just mentioned I will follow that. That means I will print blank take a lash print dollar in the beginning then I continue in the loop by cross checking corresponding to each b whether there is a or not. So, if there is a take a right move print blank take a r hash take a left move if there is b then print blank take a lash and continue in this loop. If the input is in the given format a power and b power n then after cross checking a for the b then you will come to this branch here you will just go through the blank. So, the blanks. So, what I am writing here dollar bar of course I know they are all blanks and then finally I will print s through this branch here. Otherwise I give the exit clauses here for example, at this branch if you are not encountering a you may encounter blank you may encounter blank symbol means r b if you are encountering blank symbol that means corresponding to b there is no a there appropriately we are you know printing no. If you are encountering b the similar way that I have handled to print no and in this situation corresponding to you know b I have encountered I have encountered a and I went r hash when I take a left move if I encounter a it is similar to you know you are you are having it is not of the form a power and b power n. So, there also I am printing in. So, the decider is designed like this this we this kind of things we have discussed earlier as well. So, now if I consider this decider to decide this language a power and b power n how many steps it is taking. So, what is the time function associated to this particular turing mission which is deciding a power and b power n. So, let us look at that analysis look in the very beginning here in this branch it is taking at this one move and if you go to this upper branch where you are encountering blank there you can clearly see there are three moves. So, as I had written earlier if you write like this then things will be little bit clear to you. So, here it is taking one step and here you require three steps if I go to this branch what is happening here you have to arise if you encounter a you have to arise everything and after that you have to print no it is then as explained earlier you have to arise everything. So, after this one step you require that two n plus three steps if you take this branch here you are printing blank then a lash printing blank means one step a lash means you have to come all the way to the left hand. So, n number of cells n input length of n. So, you have to take n number of steps and then you will take one step to print dollar there then right move right move takes one step and thereafter you continue in a loop and see. If you look at these branches if it is case of no if it is not in the given input format in this branch if you carefully observe you know you are encountering this branch means you are almost like you know you have done some matching through this loop and at the end of that you know for corresponding to a b you do not have an a, but you have arise everything. So, roughly you are in between the input that means roughly n by 2 cells ahead from the left hand. So, I may say roughly for roughly to say I will put a circle symbol here. So, roughly n by 2 steps that you take and then what do you do after taking n number of n by 2 number of left moves then you take you will dollar you will print again back to blank then take a right move then print no then take a right move here there are 4 steps. So, n by 2 plus 4 steps in this branch if you go to this one r hash r hash means you know from this position you have to go to the right end, but I am not very clear that how many cells so far I have arise or whatever. So, in the worst case what will happen in the beginning itself suppose if you have the mismatch. So, the length of the input whatever is given so that much you have to go I may say now here when I say r hash. So, n number of steps that you have to take plus 1 that is corresponding to taking a left move and thereafter you continue in this loop to arise that is 2 n steps and then here again 4 steps. So, now whatever the exit y a that will connect here that 2 n plus 4 these are the steps that it will take. Now, when I am exiting through this that means the input is in the required format that means you are completely arising the tape and you are going here. Of course, in each case we will be arising the tape completely, but you see that from the through this branch when you are exiting the 2 n plus 4 steps here. Similarly, when I am exiting here you see that you may be roughly half of the tape you know because you are stopping you are going towards saying yes. So, roughly you are in the half of the tape. So, here also this will continue. So, half the size and then plus 4 steps because this dollar you have to convert it to blank then taking a right move printing yes taking a right move. So, there are 4 steps here n by 2 plus 4. Now, this loop how many times it is it will run you know that if it is continuing for the entire input to reach to the middle which is a positive case here or you know it will continue and taking to this blank side also then n by 2 plus 4 steps here n by 2 plus 4. So, this is the these are the extreme cases that you will be continuing and pursuing the input. Now, let us see like how many times this loop is running and how actually it is the input is getting decreased. So, if you carefully observe that for example, here you make it blank then you go till this left hand. So, n number of steps we have counted then here you are printing dollar and taking a right move two steps and then you are making blank here then you are going till this point till this point here. So, this is a blank at this at the time then you take a left move. So, here n minus 1 steps your n minus 1 length you are going when I am saying that here r hash here n minus 1 steps that you are taking then you print blank there then l hash that time you have to take n minus 2 steps. So, in this loop what will happen. So, here you have taken for l hash n steps here n minus 1 steps here n minus 2 steps and it will keep on decreasing that you will come to the middle comes down to 1, but each of this you have a constant time added that is you know the printing and taking a move printing and taking a move the printing blank and taking a left move to cross check. So, here you can observe that the pattern is in the beginning we have already noted this 1 plus 1 plus n plus 2 there thereafter in the loop you have count like this 2 plus n minus 1 and 2 plus n minus 2 and so on 2 plus 1. So, coming down till this. So, if you note this this particular sum you can quickly calculate because here 1 plus 2 and so on plus n that is n into n plus 1 by 2 and you have n number of 2 that is 2 n. So, by including that you can see if you exclude this of course, this much only in the loop. So, this is the amount of time that you are spending in the loop now if you carefully calculate all that time. So, you can report that n into the total the time n into n plus 1 by 2 plus the 2 n 2 n by 2 plus 4 of course, here in fact in a positive sense you are getting n by 2 steps here. So, this much time if you are going this branch or this branch this is where you will get the maximum time because you are consuming the entire input in this and you are coming here. Otherwise, what will happen in between suppose this happens then in this branch you may not complete the loop like you know going till middle, but you will be taking one of these branches there we have already counted the time it is taking you know n plus 1 2 n plus 4. So, the majority of this is actually adding here there it will happen. So, or you know after completing that much that many cycles if you are doing this. So, this is in the worst case this is also in the worst case after completing almost all the cycles you are left with only n by 2, but whatever it is it is order of n here also it is of order of n. So, what do you what do you now say that this 2 n plus 4 here you can see this 3 n plus 5 this is what is the time it is it is taking and in the loop we have understood that it is of order n into n plus 1 by 2 plus 2 n. So, all this amount suppose if you add that 2 n that 3 n plus 5 or this n by n by 2 plus 4 or either this component or this component will be added. So, the maximum is 3 n plus 5. So, this component plus this component now suppose if I define a function which is a quadratic now I say this is now of order n square to loosely say or if you strictly define t of n is equal to n into n plus 1 by 2 plus 2 n that means essentially 5 1 plus 7 something like this if you define whatever the branch you take in this machine either this branch or through this branch or through this branch wherever that it is halting this is the maximum time is the maximum time it is taking is the maximum time it is taking and this function you can quickly see it is of quadratic time. Thus I can conclude that this language a power and b power n you know is decidable through this decider in quadratic time. In fact, we could come up with a precise time function for this by counting appropriately. So, through this example this is two examples I hope you understand the concept that when I am talking about the time bounded Turing machines. So, the time bounded Turing machine means a Turing machine which is you know bounded with a time function that means a decider which is bounded with a time function. So, this time bounded Turing machine concept that we are talking in to evaluate the time it is taking to decide a particular language. Now, let me come up with one more important point here whatever is a time bounded Turing machine that you consider what is the minimum amount of time it takes on an input of length n. This is actually close to the first example that we have discussed because if you are given an input of length n whatever is the parameter that you want to cross check whether it is a power n b power n or you know having at least one a or you know having a b a a sub string or whatever. Whatever is the situation what you have to do you have to arise the entire input that means you have to traverse from here you have to take a left move you have to arise it you have to take a left move and arise it this is only way that you have to traverse through this. So, that means you know you have to take n moving steps to come to the left hand. In fact, to come to the left hand you know n plus one moving steps that you require and then this n cells you have to arise that means n arising steps and these are moving steps to come to come to this n these are anyway required and after that depending on the parameter that you are cross checking you will take a right move and then here for right move means one either you print s or no in this cell that means one step and then take a right move and halt. So, that means what is happening this is 2 n plus 4 steps or minimum to decide any language. So, what I can conclude here if you are talking about a time bounded Turing machine which is deciding a particular language that any time function of a time bounded Turing machine this T n is always greater than equal to 2 n plus 4 because this time function has to take at least 2 n plus 4 steps to decide a language. So, this is what important observation. So, this is as per our convention because we have fixed convention that we will be starting from the right end of the tape and you will be you know arising the tape and continuing the complexity. Now, on contrary suppose if one wants to consider the tape you know say for example, there you do not require this kind of special symbol or anything say in a 1 a 2 and so on a n suppose this is given to you and your convention for example, if you want to start from the left end. Now, what happens you have to come back and print it is not somewhere in between you have to say s or no on the tape say for example, in the first cell or whatever. So, then in which case what you have to do here you have to put some marker say for example, in dollar then you have to traverse all this way that means n number of steps it will take because what are the parameter that you want to cross check then when you are coming back say for example, if you are arising. So, you arise all those symbols till you come here. So, that means, this is 2 n number of steps when you are coming back you have to traverse all this n number of cells and on the way you have to arise either while going you are arising or while coming you are arising whatever it is. So, essentially to go here to this end and come back and erase the tape you require 3 n number of steps and after that whatever that the parameter that you wanted to cross check depending on the language. That means, you know if I am starting from the right end I am taking minimum 2 n plus 4 steps to print s or no. If I start from this side I have to take 3 n steps to come back and again to print s or no or whatever again the required number of steps may be 2 or whatever in the first cell if you are printing s and there itself if you are halting or whatever. So, you look at you compare these 2 quantities this is say for example, 3 n plus some constant and this is 2 n plus 4. Anyway whatever is this constant this 2 n plus 4 is anyway smaller than this 3 n of course, asymptotically these 2 are equivalent, but you look at the time that you are gaining at least you know n number of steps that you are gaining. So, this is through this observation I give the proper justification when we have started discussing you know the from the tape right end because when I have discussed the Turing machines I said like you know we will be starting we will be giving the input format that we will start from the right end we will start from the right end. Now, if you start from the right end you can quickly see that you can gain n number of steps when you are discussing the time complexity. So, this is one justification that I am starting from the right end and to talk about the decidability or accepting a string and etcetera in a Turing machine. Now, one more important observation in this particular context the first example I have discussed L A that means all those strings which are having A as substring say A B star this is the language today I have discussed that A is a substring of x. So, there is at least one A in this x. We have observed that there is a Turing machine which takes time. So, T A I wrote the time for this is 2 n plus 4 and just now I have mentioned that any time bounded Turing machine any Turing machine which decides a particular language in a time t that time bound is you know is the lower bound is 2 n plus 4. So, 2 n plus 4 is less than or equal to that particular time. Now, you see for this particular language what are the decidable that we have designed that is of 2 n plus 4 time that means it is optimal it is optimal time. So, and now the point is this is a regular language that we have constructed a decider appropriately and we have decided that in time 2 n plus 4 this is the minimum time possible with any Turing machine that we have. Now, you can in fact observe that if you take any regular language for every regular language you can have a time bounded Turing machine that whose time is 2 n plus 4. There is a Turing machine decider of course, that decides for every regular language say L that decides L in time 2 n plus 4 in time 2 n plus 4 this is the time function I am giving. Now, how do you make out this you know if it is a regular language you can manipulate via states only you can you have to just scan through the tape only once that you know. And when you are designing a Turing machine appropriately you design and whatever that you wanted to cross check you just use via you know the you can you can via states that you can maintain and you scan through the tape once and may be for example, if you are starting from the right end you just scan through the tape. We know that if L is regular L power R is also regular that means, if you reverse every string in the language that is L power R we are talking so that is also regular. So, the since regular language are closed with respect to reversal either you read from left side or right side one another is same now the corresponding language that we are looking at. So, you just scan through the tape once and finally, you just take that 3 right moves while you are printing yes or no. So, the point is using that particular mechanism that means whatever the way that you design your DFA corresponding to this regular language you can appropriately you know design the states for a decider. And in fact, you can design a Turing machine which decides this regular language in time 2 n plus 4. Now, what about the converse because 2 n plus 4 is the minimum time I had mentioned now if you decide a particular language in 2 n plus 4 time that means, you just scan through the tape only once and decide the things because you do not have any other option. If I say you are deciding a language in 2 n plus 4 time as you have observed you are just scanning the tape only once and whatever that you wanted to remember you have to remember through states only. So, now the question is if you look for the higher little higher order languages that means, higher languages like you know context free or context sensitive etcetera. What is happening there you require some other auxiliary input or something else, but for regular language you do not require. So, is it only the language if for which you require 2 n plus 4 time that means, if you have a Turing machine which decides a particular language in 2 n plus 4 time is that regular that is a question in fact it is so. So, what I am saying is if M divides sorry M decides a language L in time 2 n plus 4 then L is regular in fact. So, very important observation here that means L is regular if and only if there is a decider that decides L in time 2 n plus 4 time. So, this 2 n plus 4 time the minimum time is you know for regular languages for the class of regular languages you have. So, what I can now write here through this observation time as I have introduced the notation time 2 n plus 4 because here I am writing the time function is equal to the class of regular languages the class of regular languages. So, this is a very important observation. Now, you can take it as an exercise to prove both the parts because I have just discussed the ideas only you take it as an exercise and prove both the parts that means, you know L is regular if and only if there is a Turing machine that decides in time 2 n plus 4 an exercise.