 Hello friends, today we are going to see one more sequential searching algorithm that is shift or algorithm. So, learning outcome for this session is students will be able to find text positions where the pattern occurs using shift or algorithm. So, previously we have already seen KMP, BM and medium algorithm, today we are looking for this shift or algorithm. So, what is the shift or algorithm is it is based on bit parallelism. So, it takes advantage of intrinsic parallelism of bit operations inside a computer word of W bits. So, number of operations that will be performed will be cut by the factor of W. So, that is at most. So, here shift or algorithm use bit parallelism to simulate the operation of non-deterministic automata that searches the pattern in the text. So, look at this. So, assume that the pattern is a, b, a, b, c. So, this is the non-deterministic automata for this particular pattern. So, automata is simulated in O of m and time that is the worst time. So, shift or algorithm achieves O of m and divided by W worst case time because we are doing it in parallel. So, where m is the length of the pattern and n is the length of text. So, in shift or algorithm what is the first step is that algorithm first build a table b which is of the bit mass table. So, for every character a bit mass is going to be formed. So, of course the characters from the pattern. So, mass in B of q is has the ith bit set to 0 if and only if P i is equal to q. Now, what do you mean by this is that? So, in the previous we are having the pattern a, b, a, b, c. So, here so a, b and c are the characters which are present in the pattern. So, any other character will be represented by this star character. So, here there are 5 characters in the pattern and therefore it will be the bit mass of 5 bits. So, b 1, b 2, b 3, b 4 and b 5 and our pattern is a, b, a, b, c. So, here look at the character is a wherever there is a in the pattern that bit we are going to set it to 0 and that is why the first and third bit has been set to 0. For b now the occurrence is at the second and fourth position which will be set to 0 and then in c it has it is only at the last position that is why it has been set to 0. So, every other character will be denoted by this since they are not present in the pattern no bit will be set and this bit mass, bit mass will be of all ones. So, how to represent it? So, this was bit mass. So, from b 1 to b 5. So, bit mass for a will be 11010 that is here 11010 we are starting with b 1 to b 5. So, it will be in the reverse order. So, for b it will be 101101 and for c it will be 0 4 times 1. So, for any other character which is not present in the pattern it will be all ones. So, the first step is build a bit mass table. Now pause the video here and then find out the bit mass pattern for this particular table for this particular pattern. So, of course there are six characters again the same wherever there is 8 will be set to 0 wherever there is b it will be set to 0 and again the third character is c. So, these are all patterns I hope you have understood how to find the bit mass for every character which is present in the pattern. Now the next step is that searching a particular pattern in the text. So, we are going to use it automata. So, initially we are going to set the keyword to all ones. So, this is going to be the state of every what you can say that every character search d 1 to d m. So, whenever d i bit has been set to 0 it means that that state number i is active. So, of course when this d m bit is set to 0 it means that the last state which is accepting state is active and match has been reported. But if the pattern or the text is finished and this d m bit is not set to 0 it means that we have not found the pattern. Now what are the operations that we are going to perform in the shift or algorithm it is the shift operation which is going to be there and the second one is the OR operation. So, initially we are going to start with the initial state of the automata and all d bits will be set to 1 since we have not processed any character. So, after reading every character t j from the text the data that state is going to be updated and how it is going to be updated. So, the new state will be d dash is equal to left shift the current state by 1 bit and then OR it with the bit mass of the character which has been read and hence it is called as a shift or algorithm. So, pattern longer than this computer word size the algorithm uses m by w computer words for simulation. Now let us look at the example here again the pattern is taken as an a a b a ok. So, this is what the automata for non deterministic automata for a a b a. So, first step is find a bit mass. So, this is the bit mass for now there are only two characters that is why we have taken character a and b. So, for the rest characters it will be all once. So, bit mass for a is 0 1 0 0 and for b it is 1 0 1 1. Now let us look at this. So, here is the text from which we are going to find out the pattern a a b a ok. So, here initial state is of course 1. Now the first character is a whose bit mass is 0 1 0 0. So, what is the first step? Left shift by 1. So, left shift means all will be shifted to the left and then upended by 0. This is a new state. Now do the auring of these two and resulting will be. So, d 1 bit has been set to 0 it means that we have read a character and which has been matched to the pattern and that is why we are moving to the next state. Now the next character is again the next character is a whose bit mass is 0 1 0 0. So, again left shift by 1. So, 1 1 0 0 do the auring and then the second bit has been set to 0. It means that again a a has been matched to the pattern and we have moved to the next state. Now the next character is b ok. So, b the bit mass for b is 1 0 1 1 again left shift by this state. So, it will be 1 0 0 0 auring it with this. Now the third bit has been set to 0. So, we are in the third state and that is why again a a b has been matched and then we will go in for the last character which is again a. So, again left shifted by 1 and then it will be 0 1 0 0. So, here 0 bit has been set to 0 d m bit has been set to 0 it means that we have reached to the accepting state and pattern is found the first position is found. So, pattern is found at the position of 1. Now, we have to find the more patterns. So, once the pattern has been found from where the position we are having we are moving to the next character and that is why now we are moving to the next character. Again the process will be repeated here. So, again a will be read and then it is going to be 1 1 0 0 then it will be updated again the bit has been set. So, this is going to move to the first state. Next character will be read. So, next character is now here b ok. So, this is going to be 1 1 0 0 and if we look at this no bit has been set it means that what is our pattern a a b a and what is the text that we have read a b. So, here it is a mismatch and that is why there is no transition from this state to b. Hence, it is not matching then we have to move further. I hope you have understood this state. So, again we are moving to this b. So, pattern so bit mass for b. So, again left shift do the oring like this look at this again the result is 1 1 1 1. It means that the pattern is not starting with b and hence we are not getting the next state. So, again move to the next step. So, thus we are repeating the steps. So, here the same the result a is matched that is why it will move to the next state. Again this a is matched that is why we are moving to the next state and the next character is now c. So, here 1 0 0 0. So, here it should be actually c and then it has not found. So, here it should be 1 1 1 1. So, the next character will be a which is going to be processed. Again the next character is going to be a. So, this is a this is again going to be processed and for d it is going to be the mismatch because d is not present in the pattern. So, I hope you have understood the process. Now you can pause the video and then you can move further text and do the operations. So, this will be moved to again a and then we will start again this a and d will not be matched and so on. So, let us hope that you have done the process and now I have moved to the process. So, you must have created the steps for this. So, again a is there. So, same process will be repeated. So, this is going to be a is matched then the next character is a. So, second bit has been set to 0 again the next character is now b. So, third bit is going to be set to 0 every time we are doing left shift and then aoring. This is a and then the fourth character is again a. So, last bit has been set to 0 it means that we have found a second pattern. I hope you have understood the process how the shift or algorithm is working. Now why we are moving to the next position after finding the pattern or after mismatch. Let us look at this example. So, here a a a b a c is the text and our pattern is here a a b. What will happen? So, first a is matched. So, we will move to the next state. Again a is matched then we will move to the next state and then b is mismatched here. So, if it is mismatched here we cannot directly move to the next step because if you look at this now this is the a a b pattern which is overlapped and that is why we are moving to the next position for finding the all patterns. So, some of the characters from the pattern are repeating or are overlapping in the text that is why when there is a mismatch or match we have to move to the immediate next position and hence what that is what we have did in the previous example. So, this is how shift or algorithm works. So, this is the reference. Thank you.