 lecture that is on an implementation of Q using array. So these are the learning outcomes. At the end of this session students will be able to explain a linear Q in the data structure. So as we have seen in the previous lecture that is the Q which follows the first in first out a linear data structure. So whenever you are going to add the data into the Q it should be added from the rare end. And whenever you are going to delete the data from the Q you have to delete from the front end. So that's why we required two pointers to keep the record of an Q that is rare pointer and the front pointer. So now we will see the implementation of Q using a C language. So these are the algorithms for the insert operation. So now initial we are going to take the value of rare equal to minus one and front we are going to keep it at zero. So means if the size of an Q is three. So we are going to have the size of Q will be three here that is a of zero, a of one and a of two. Means this is an array size of three. So this is a rare end and this is front end. So while inserting the elements in the Q we are going to insert every time from this rare end. And whenever you are going to delete the elements from the Q we are going to delete it from the front end here. So before inserting the data every time we have to check the full condition that is a full condition. So that is given by rare equal to equal to size minus one. So size is what three and minus one means where that is r is equal to equal to two. But it is not the case where r is pointing where r is equal to minus one. So here we can insert the new element in the Q here. So after inserting the new element in the Q then new Q will look like this. That is 10. So after inserting this 10, so we have to increment the values of r and f here. So initial f was pointing at this position. Now r was pointing at minus one. So now r is going to point at a of zero here. So as we know that front and rare will always point to the, this is the last element and this will be the pointing towards the first element respectively. So 10 is only the element in the Q. So that's why this is the first element and this is the last element in the Q here. So suppose if the user wants to insert one more data into the Q, so the same procedure we have to follow or we have followed in the previous thing. So what things? So we have to check the full condition that is r is equal to equal to size minus one. Now size is what three minus one. So it will come to be a two. But actually now r is pointing towards a of zero and f is pointing towards a of zero only. So the space is still available here because r is pointing towards the a of zero. So 20 can be inserted here and r has been incremented by plus one here. That's why now suppose one more element if you want to insert in the Q that is a of zero, a of one, a of two. So where this is f and this is r. So front is pointing towards the first element in the Q that is 10, this is 20 is pointing towards the r. So one more element if you want to insert we have to check once again the size two. That is full condition r is equal to equal to size minus one that is two. But r is pointing where r is pointing towards one. So this condition is not satisfied here. So we can insert one more element here. So that is 30. So now what happens if this 10, 20 and 30 r is going to increment by one and f will be at same position here. So that's why when you're going to insert the new element in the algorithms step two is what rare equal to rare plus one here. So that's why. So one more if the user wants to insert the new element in the Q here. So we have to check the full condition here. So that is 10, 20 and 30. This is r and this is f. So where r is pointing now r is pointing towards the second and r is equal to size minus one three minus one r is equal to equal to two. Yes, this condition is satisfied here. We cannot insert the new element in the Q. So it will show then these Q is overflow here. So this condition is executed here when this condition is satisfied here. Okay. So f is pointing towards the first element r is pointing towards the last element here. Now let us see that algorithm for the delete operation. So for the delete operation so in the same manner for insert operation we used to check full condition same for delete we are going to check empty condition. So as we have seen in previous Q that is 10, 20 and 30. So f is here and r is here now. So we used to insert the data from rare end and we used to have now going to delete from the front end here. So if you want to delete the element we have to check the this condition that is an empty condition. How we are going to check we are going to check by this that is r is equal to equal to minus one and means the compulsory operation and front is equal to equal to zero. So this condition is satisfied but this condition is not satisfied as r is pointing towards the a of 2 as this is a of 0 and this is a of 1. So this condition becomes full. It is done with r condition that is r f is greater than rare here but this condition is not satisfied this is also not satisfied hence we can delete the operation. So you are going to delete the data from the Q means front is going to increment by plus 1 that is front is equal to front plus 1. So this will be 20, 30 and this f is going to increment by plus 1. Here is r that is f from the deleted position. So front is incremented by 1. So now this is the first element in the Q and this is the last element in the Q. Suppose if user wants to delete one more element from the Q here what happens you are going to delete this means your f will be at this position and r will be at this position only. So now this is the position now suppose user wants to delete one more element. So every time we have to check this condition that is r is equal to equal to minus 1 ending with this. So this is deleted means what happens here r is going to be incremented and this from this. So front will go and initialize to 0 and r will be initialized to minus 1. So 30 deleting this so this goes to this position. So what happens this condition is going to be satisfied because f is at equal to equal to 0 and r is equal to minus 1 here. So this condition becomes satisfied here. So that's why 30 so what happens this condition becomes satisfied that is f is greater than r because r is pointing towards a of 2 and f is going to be greater than a of 2. So this condition is satisfied that's why your Q is in now empty position. So your pointers will be initialized to f equal to 0 there. So now this condition is satisfied here. So that is known as a delete operation. So this is for the display. Now suppose user wants to display how many elements are there in a Q. So now this is f and this is an r. So we can have to write an a for loop for that i is equal to front i is less than equal to rare i is plus plus. So i is at which position a of 0 1 a of 2. So i is equal to 0 this condition is satisfied i is less than equal to rare. Rare is pointing towards 0 means i is less than equal to 2 and i plus plus. If this condition is satisfied you are going to increment means it will print 10. If this then your pointer is going to be incremented by 1. So it becomes 20 in this manner 30. This condition becomes fails means we are going to come out from this loop here. So that's why if you want to display we have to make use of an the for loop for that. So that is i equal to front i is less than equal to rare and i plus plus. So this is for the algorithm for display. Pause this video and answer this question. If the elements a b c and d are placed in the queue and are deleted one at a time in what order will they be removed? So the answer is a b c and d. So what are the drawbacks of a linear queue? So even if there is a space in the queue we cannot insert the data into the queue. For example what we have seen in the video if we have a size of an queue is three elements and we have inserted three elements in the queue and delete some data then the queue has some space. But at that condition we cannot insert the data into the queue because we have already incremented the pointers that is r equal to pi plus 1 here and not we are going to initialize to r equal to minus 1. So what happens? This is the memory utilization problem comes here. Even if there is a space in the queue we cannot reinsert the data. So such drawbacks of a linear queue can be solved with the help of a circular queue. So these are my references. Thank you.