 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. Initially we will put one question try to answer it to implement the castra shortest path algorithm on unweighted graph so that it run in the linear time what data structure will be used. Here four data structures are given Q, stack, hip and B tree. Now this is a shortest path algorithm when we want to reach from A to C then this will be shortest path A to B B to C as it is a unweighted graph. So smallest node will be considered and A to D and D to C that will be longest path. Now here as we have seen that is the shortest path is unweighted graph. The smallest number of edges must be traversed in order to reach the destination in the graph. So Q as it is having first in first out we can keep smallest edges and we can use that deleting smallest edges. So if we use Q we can get the shortest path in linear time. Next question number two. Suppose a circular Q of capacity n-1 element is implemented with an array of n element means the Q is of n capacity and we can keep from 0 to n-1. Assume that insertion and deletion operations are carried out using rare and front as array index variable respectively where initially rare is equal to front is equal to 0. The condition to detect Q full and Q empty are now here some four conditions are given where we have to find out which is correct answer for full Q and empty Q. Now we will see the circular Q, this is a circular Q, this is a linear Q where we are having rare and front here we are having rare and front and once we are full again we are reaching to the 0th position. After finishing the n position we are reaching again to the 0th position but in the linear Q we have to go from 0 to the last and we cannot come to the 0 though it is a empty. Now we will see this head it is always point to the location from where next deletion takes place from the Q. So head or front is the pointer where the location from where next deletion will be take place and rare or tell is pointing to that location where we can insert a new number. Now in the circular Q as I said we can use this wrap around features in the circular Q when the tell or head is at the index last index n minus 1 next operation will be bring to them to the index 0 and we will reserve one empty spot in order to detect the overflow and under flow conditions. Then the element is in the Q resides in the location from like this Q head Q head plus 1 up to the tell and when tell plus 1 again it will be going to the head. So this is the wrap around condition now here we can see that when nothing is there when it is empty. So at that position front is equal to rare. So this is the empty condition. So we can write empty condition is equal to front is equal to rare. Now we will start to include some values insert 14 the rare will be now next it is showing which is the next position where we can insert the value. So here your rare is there I am inserting here 22 again your rare will be next 13 is included like this we are incrementing the rare and when I am deleting in this case now front 14 will be deleted now front will come to the next value which can be deleted from the Q. So 22 is the next value so front is showing the when I am deleting 22 it will come to the 13. So like this you can increase the front and rare as per the operations. Now in this case when I am inserting all the value that time my rare is reaching to the nearly end condition and front is to the value now it is from 0, 1, 2. Now front is at the second condition and I want to insert one more value so I can wrap around condition. So here the rare has come to the 0th position now it can be come to the next position it is showing that is the first position. Now here it is a full condition now if we can see that is the full condition. So if I am incrementing rare by one I am reaching to the front when I am doing rare plus 1 mod n, n is the capacity so this is the full condition and empty condition as we have seen at the start when it is a empty rare is equal to front. So A is a correct answer a priority Q is used to implement a stack S that stores character push C is implemented as insert in the push we are pushing C and in the insert we are having that Q C is the character we are pushing and K is the appropriate integer key chosen by the implementation. Now pop is implemented as delete mean means minimum value has to be deleted from the Q for a sequence of operation the key should be chosen and which key should be appropriate for this. Now here we are implementing a priority Q first that we are using stack and that priority Q is on the basic or base of minimum should be deleted first. So in this condition which will be the appropriate option non-increasing order, non-decreasing order, strictly increasing order and strictly decreasing order. Now as here we have seen that implementing a stack using priority Q here it will be stack implementation is always last in first out order. So in stack last element is pushed should be popped out first in the priority Q minimum element is given the highest priority. So it should come out first minimum value. Now whenever we call delete minimum it will be popped the element with the minimum value then the minimum element should be inserted last or inserted should be in the decreasing order means in the stack it should be insert into the decreasing order and it should be strictly decreasing order. Why non-increasing order that will also work but that will be one disadvantage that for four two elements when they are equal value the priority Q will pick any one of the randomly. So which will not be case in the stack so we have to implement with the strictly decreasing order. So as we have seen this question is priority Q and we have to implement using the stack and we have to push that in strictly decreasing order so that when we are deleting that value the minimum value should be come out first as it is having the highest priority. Thank you.