 Hello, welcome to the session data structure stack gate questions. At the end of this session the students will be able to solve data structure stack problems. Initially, we will see first question and pause the video and try to answer which of the following permutations can be obtained in the output in the same order using a stack assuming that the input is the sequence 1, 2, 3, 4, 5 in that order. So, we have to find out which permutation is possible using stack and pushing the numbers in order 1, 2, 3, 4, 5, but pop in any sequence. Find out the answer. So, we will see the answer here. So, the restriction is to push the numbers in the sequence. So, we will push that number 1, then 2, then 3, then 4 and 5. For this first option we will check here that is we have pushed 1, then 2 and then 3, then we have popped 3. Next we have pushed 4, then we have popped 4, then we have pushed 5 and then we have popped 5. Then we need to pop 1, but in the stack we are having 2. So, this option is not possible. Now, next for this option we will see again 3 is there, we will push 1, then 2 and 3, then we will be popping 3. Next we are pushing 4 and popping 4, then next we are pushing 5 and popping 5. And then top of the stack is 2, then we can pop 2 and then lastly we can pop this remaining 1. So, this option is correct. We will go for the next question. So, here consider the following C program is given in that it is defined end of file as minus 1. So, we need to read the program up to the end of file. Then one function is given wide push which will be push the argument on the stack. Then pop in this pop the top of the stack can be popped. Next is error the flag is there flag error. Then the C program is there. In this program while C is equal to get care, we are going to get care one by one till end of file. And if that character C is digit, then we are going to push it push C. Next if it is not a DJ, then it will be any sign plus sign or multiplication sign. That time we are going to pop top of the stack as m, next top of the stack as n. Then r is equal to whatever we popped m and n we are using that when plus sign is there n plus m will be there and when otherwise n multiplied by m. And whatever the answer resultant answer r is there that will be pushed on the stack. And if nothing is there means addition, multiplication or any care digit is not there, then it will be passing as an error. Finally, when all this done we are popping the stack. So, based on this program a question is given what is the output of the program for following input. So, what will be the output of the program for this given expression phi u 2 multiplication 3 3 2 plus multiplication and plus. And the options are given 15 25 u 30 and 150. Now in this case using this program we will try to evaluate this post fix expression. So, in this case it is written that if the current character is a digit we are pushing on to the stack else if the current character is operator it pops 2 element and then performs the operation. So, we will see the initially the stack is empty then we are having phi u that is a digit. So, the digit will be if it is digit it will be pushed. So, phi u is to be pushed on the stack then next is also digit that is also pushed on the stack then we are having the multiplication sign. So, it pops 2 elements what we are pushed on the stack that is first phi u and then 2. So, n is equal to 2 and m is equal to phi u and multiplication will be 10 and that will be again pushed on the stack. So, 10 will be on the stack. Next after that we are having 3 then next value is 3 and then again 2. So, all 3 values will be pushed on the stack. Next we are having addition sign. So, addition sign will be here that time top of the stack will be 3 and 2. So, addition 3 and 2 will be phi u that will be again pushed on the stack. Next phi u will be top of the stack and multiplication sign. So, phi u and before that we are having top of the stack is 3. So, phi u and 3 will be 15 again that will be pushed on the stack. And finally, we are having that addition sign that time we are having top of the stack 2 numbers 15 and 10 will be add that that will be 25. So, the correct answer for this is 25. So, one more time I will show how the stack is operating. So, first initially we are pushed phi u and then 2. Next we have encountered multiplication sign. So, multiplication sign between 2 and phi u the result will be 10. So, that is pushed on the stack. After that we are having 3 values 3 that is pushed on the stack as it is a digit next 3 and then next 2 is pushed on the stack. Then we have found addition sign. So, top of the stack will be 2 and 3. So, 3 plus 2 will be phi u. So, that will be the top of the stack. Now, next we are having the multiplication sign. So, top of the stacks are phi u and 3. So, multiplication sign it will be given 15 and we are already having 10. So, last we are having multiplication addition sign 15 plus 10 is equal to 25. So, the answer is 25 here. Now, here one more question try to answer it how many stack will require to implement a queue. So, here options are given 2, 1, 3 and 4. Queue is the data structure where which number is inserted first that will be deleted first. So, here 1, 2, 3. So, that insertion is in the sequence 1, 2, 3 and deletion will be in the same sequence 1, 2, 3. So, the basic concept here we will see that how we can implement a queue using 2 stacks. So, when we want to insert only we are pushing in the first stack and when we want to delete we will check if stack s2 is empty or s1 is empty then we can write queue is also empty. Otherwise if we are having some value in the stack then till the stack is going to empty we will pop s1 and then we will push it into the s2. Now, here we can see that this is the queue 1, 2, 3 we are having. So, as here written when we are inserting the value just we have to push. So, we have to first one I have pushed one to the second pushed the second third as third. But when if I want to pop it that will be in the reverse order. So, 3 will become first 2 and 1. So, that will not be queue. So, to implement queue using stack after this stack pushing when we want to delete s1 has to push to the s2. Now what will happen we will see that this 3 will be pushed into the stack s2 then we will push 2 then we will pushed 1. Now next when we are popping s2 so this first will be popped then 2 and then 3. So, how the queue works in the same way this stack will be work with the help of 2 stack we are implemented queue. So, here our answer will be 2 stacks will be required to implement a queue. Thank you.