 Hello, welcome to next lecture that is on circular cube. So these are the learning outcomes. At the end of this session, the students will be able to illustrate the circular cube in data structure. So now we'll start with the circular cube. Previously what we have studied in the video lecture was implementation of linear cube. As you know that Q will follow first in first out linear data structure. But even if you have the memory space in the Q, we cannot insert the new data into the Q. So that's why that is to make the effective utilization of memory. We are going to see the circular cube. So first we are going to see the algorithm for the insert operation. So in the same manner what we have studied in the linear cube that is for the insert operation we are going to check the full condition. In the same manner if you are going to delete the atoms we are going to check the empty condition. So why we are going to for circular cube? As we know that in the linear cube if you delete all the elements that is 10 20 and 30 now this is R now this is an F. If you delete all these elements the F will come here but the R will be at this same position. We are not going to connect this to the first position that's why the memory utilization is not done properly in the linear cube means what to make the effective utilization we are going to connect the last end of the Q to the first end for proper utilization of memory means we have a space then we can reinsert the data. So that is known as an the circular Q. Logically we are going to connect that is this end to the this end here. So we'll start with the an algorithm that is an insert operation. So this is the condition to make the full. So this is the full condition. So this condition is appear so you can write Q is overflow. So if it doesn't happen so we have to go for the next step that is an F whatever you're going to conditions are there. Now suppose we are going to take the size is equal to 3 here. So now I'm going to draw the circle because we are going to connect logically that is last end to the first end here. Now suppose this is a of 0, a of 1 and a of 2 here. So now before inserting the new elements every time we are going to check the full condition that is F is equal to equal to 0 that is ending with R is equal to size minus 1 or condition either this condition or either this condition is satisfied you can say the Q is full that is F is equal to equal to R plus 1. Now we are going to insert the new element that is an 10. So whenever we are going to insert the new element initial F and R is equal to minus 1. So they are pointing towards the minus 1. So this condition is satisfied when F is equal to equal to minus 1 then we can have F is equal to and R is equal to 0 means both the pointers are going to be increment by plus 1 here. So that's why it is F is equal to equal to minus 1 means F is equal to equal to 0. Now this condition will appear only once when we are going to insert the first data in the circular cube. If this condition is not satisfied so the normal condition will appear that is R plus plus. Now if you want to reinsert the data means you are going to insert the new data so at that time you can say that is R is going to incremented by 1. So this will be F and now this is an R. So this condition has been incremented because this condition is then R is equal to 0 this is most important condition. So from this condition only we are going to connect this end to the next end here. So this will happen. So now suppose one more data if you want to insert that is F that is 10, 20 and 30 so R will be at this position here. So now this condition is full. How you are going to check this if you want to insert 40 you cannot insert that data that is 30 this is R, this is A of 1, this is A of 2, this is A of 0, 10, 20 and F. Now going to check F is pointing where here 0 and size minus 1. Size is what we are going 3, 3 minus 2, 3 minus 1 so it is pointing so R is actually pointing towards 2. So this condition is satisfied this if doesn't happen so this is known as an R condition. So this condition is satisfied so this is in full condition so we cannot reinsert the new data. So when this condition will appear that is R is equal to equal to size minus 1 so when you are going to delete this element so F will come here. So what will happen if you delete 10 so what happened your first now F will be incremented by this position 1, 20 and this will be an R. So in linear queue what happened if you want to reinsert the data that is not possible because we have not connected logically last end to the first end here but in circular queue by writing this condition if R is equal to equal to size minus 1 we have seen this in the year that is R is now where 2 that is size minus 1 so what we happen we can insert the new data that is an 40 so what will happen this will be at this position R is incremented by plus 1. So in the same manner if you want to do one more F is deleted so the space is available you can reinsert the data that is effective utilization of a memory here. In the same manner we are going to see the algorithm for the delete so in the same manner delete operation we are going to check the empty condition here so what we have taken that is the size we have taken 3 so already what we have seen 10, 20, 30 this is F this is R so if you want to insert the data R is incremented by plus 1 if you want to delete the data that is you are going to increment the F pointer here. So if you delete 10 so the new queue will be look like this F this will be empty 20 and 30 this will be an R so this condition is written here F plus plus here so when this condition will happen F is equal to equal to R then we have to point R is equal to F equal to minus 1 here so all this condition before inserting we are going to see that our empty condition that is R is equal to equal to minus 1 ending with F is equal to equal to 1. Now what we will see that if you delete this one more delete 20 so what will happen so F come here and R will be at same position that is A of 2, A of 1 and this is A of 0 so suppose now what happened this condition will be executed when F is equal to equal to R then F equal to so if you delete 30 so what will happen so if you delete this so both are pointing towards the same element so F in equal to re-initialized to R and F equal to minus 1 so Q is in empty condition so if you delete the element from the queue so this condition will be executed as F R and F is equal to minus 1 okay so when this condition will occur F is equal to size minus 1 so if F is at this position okay and R is at this position that is 10 20 and 30 here so if F is equal to equal to size minus 1 so F is equal to 0 if you delete this element that is delete 10 so what will happen so F will point towards this element and R will be at this position only that is in this position means by connecting last 10 that is A of 2 to A of 0 that is logically we have connected here so F is going to incremented so how we are going to do this so we are going to do this by the modulus that is an mod of this here okay so these are the algorithms used for and delete operations by using this an algorithm we have to implement the C program here so for this you should remember all these three conditions that is F is equal to equal to R then what we have to do if F is equal to equal to size minus 1 what we have to do and normally F is incremented by plus 1 here okay so now we will see the algorithm for the display here so now in display what we have to do that is we have to display all the elements how many elements are there which are the elements in the queue so these are the queue that is 10 20 and 30 this is A of 0 A of 1 A of 2 here so by deleting the elements okay so in the same manner if you want to bring the data so what what we have to check is the queue is empty or not how you are going to check this F and R is equal to equal to minus 1 if this condition is satisfied your queue is in empty so you cannot delete the elements from the queue so that's why so every time whenever we are going to display we have to check this condition that is Q is empty or not if Q is not empty then we have to go for an for loop that is I equal to F I is not equal to R and I is equal to I plus 1 mod of size so here size what we have taken is 3 so this is most important as you know that in for loop this is for initial condition this is condition and this is increment or decrement here okay so now I is equal to F means F is where pointing that is F of A of 0 here so here I value becomes 0 okay I is not equal to where till where you are going to check this condition that is I is not equal to R so where R is pointing where R is pointing towards the 2 so that's why I is not equal to 2 so I 0 0 is not equal to 2 so that's why this condition is satisfied you are going to increment this so it will print 10 so we are going to increment the value of and this so I is what 0 plus 1 mod size of 0 3 so 1 3 0 divided by 0 that comes to be an 1 so this is incremented by plus 1 here same manner it is pointing towards the 1 it will be pointing towards the 2 so this way the condition is going to be incremented here so this is the most important thing that mod we are going to connect all the logical end from a of 0 a of 2 to a of 0 here okay so it will print all 10 20 and while leaving these elements we are going to print the Q of R that is 30 so this condition will satisfy till two elements are printed here and one more element if you want to print you have to print the Q of R while leaving the this for loop here so this is the regarding the algorithms for insert delete and display for the circular Q so now pause this video and answer this question if if it is a normal Q if we implement using an array of size that is max underscore size to get full condition so when what will be the condition for that so are the answer is rare equal to max underscore size minus 1 so these are my references thank you