 Hello welcome to the session data structure gate questions. At the end of this session the student will be able to solve data structure problems. Now this is the first question we are going to handle that is 2007. Suppose you are given an implementation of a queue of integers the operations that can be performed on the queue R is empty so it will be written the value true if the queue is empty false otherwise delete queue it will be deletes the element at the front of the queue and return its value. So it will be return value whatever in the queue which is deleted then it will be insert queue comma I so it will be insert the integer I in the rare of the queue. Now we will consider the following function and we will answer this void f queue integer I if not is empty queue then I is equal to delete queue and f queue and insert queue comma I. So what operation is performed by the above function f it leaves the queue unchanged reverse the order of element in the queue deletes the element at the front of the queue and insert it at the rare keeping the other element in the same order or empty is the queue. Now we will see this function how it operates now we are having this queue 1 2 3 4 5 okay here as per we have seen this first we will check if it is a empty queue not then we are deleting that queue element and we are keeping that I and then we are checking that f of queue and then insert that queue comma I. So here what we are doing is we delete element from the queue till it becomes empty we are checking if it is not empty then we are deleting the element and after that we insert that last deleted element at the rare of the queue then and this is the recursive call and this will be eventually unwind to give all the elements in the reverse order just we are seeing that see here first 1 2 3 4 5 we are checking this queue if it is not empty we are deleting the value. So here first we are deleted 1 then next 2 3 4 5 is there so that value is kept somewhere in the stack and then second if we are checking the queue is empty or not no then we are deleting the front element that is 2 then we are having remaining value is 3 4 5 again we are checking the queue and deleting the value as it is not empty then next we are deleting next element as it is not empty 4 element will be deleted next 5 now here this is the last element we are checking it is not still empty so we are deleting 5 and then after this our queue will be empty then we are going to insert that values which is deleted last that will be inserted first so we are putting 5 then 4 then 3 then 2 and 1 so it is a recursive call we are going recursively how we are deleted and removing from the front and inserting from the end so that means the last element will be which is last element deleted is 5 and that will be inserted into the queue as a first element then next is 4 that will be second element then next is third 3 that will be next third element 2 will be fourth element and 1 will be fifth element so this is a queue which are going to be reverse so these four operations are reversing our queue so this is our final answer reverse the order of the element in the queue now next question is a single array A 1 to max size is used to implement two stacks the two stacks grows from opposite ends of the array variable top 1 and top 2 where top 1 is less than top 2 points to the location of the top most element in each of the stack if the space is to be used efficiently the condition for stack full is we have to check when the stack full is used there are four different options are given we will see how it operates so this is our question here a single array A is there it is from 1 to max size it is used to implement two stacks in the same array we are implementing two stacks and they are growing in opposite direction it is growing from the first two three four like this and this is growing from n n minus 1 n like this so now the point of the location top most element in each of the stack if the space is used efficiently means fully the space is used when the condition for stack full is will be occur now here if we are having 10 size of the array and we are putting 1 2 3 and top is increase in this way now when it will be 4 and the same time when this stack 2 is also going to be full so it will be 10 9 8 7 6 and it will be here we are already full up to 4 and it will become up to 5 so when both stacks are full what will be the operation now here my top size here for the first is 4 and next is 5 so when top 1 is equal to top 2 minus 1 so here top 2 is 6 sorry 5u 5u minus 1 is equal to top 1 4 so these are the two stacks and they are implementing in this way and our answer will be top 1 is equal to top 2 minus 1 so whatever the top 2 value is there that minus 1 will be the top 1 will be there so this is the efficiently use of the array to full the stack so here one more question is there suppose each set is represented as a linked list with the element in the arbitrary order which of the operation among union intersection membership cardinality will be the slowest here we are having different operations intersection union membership and cardinality intersection means which common elements are there in both list that we are going to print in union union means both condition L2 and L1 we are going to print but only once we are not repeating the same value again and membership it will be travels all the node of L1 and L2 and look for a match means only it is having a one run and cardinality is only the count how many nodes are there so here different options are there union actually when we are having two operations it will be more slow so when union is there and intersection union will not be slow then intersection and membership membership is having only the just as we have seen traverse of all nodes but intersection we have to choose who is the common one so next membership and cardinality it will be very fast as both are having just here counting and here just traversing so only two options are remain B and D so in union we are going to match both cases and we have to find in intersection also we have to find out comparison between both members so D option will be having very slow comparative to the other one thank you