 Hello welcome to the session data structure stack gate questions. At the end of this session the student will be able to solve data structure stack problems. First we will put one question, try to answer it, a program attempts to generate as many permutation as possible of the string A, B, C, D by pushing the character A, B, C and D in the same order onto the stack. But it may pop up the top character at any time, which one of the following a string cannot be generated using this program. Similarly the question is, you have to push the characters A, B, C, D in the same order and you have to generate one of the string, try this. Now here we will try this, if I am pushing A then B then C and then D. Now we will check how the different popping options are there. In this first option A has pushed, A has popped, B has pushed, B has popped, C has pushed, C has popped and D pushed, D popped. So this string is possible. In the second, D, C, B, A, so all A, B, C, D we have pushed, then D has popped, C has popped, B has popped and then A is popped. So this is also possible. In this case after A, B, C, C has popped, then B has popped, then A has popped and lastly D has pushed and popped. But in the last case A, B, C we have pushed, C has popped and after that they want to pop A but it is not possible because B is there in the series. So this is not possible option. So a string C, A, B, D cannot be generated using this program. Now we will see the next question from 2007. The following postfix expression with single digit operands is evaluated using stack. Now here one postfix expression is given and they are asked about this. Note that power is the exponential operator. The top two elements of the stack after the first star is evaluated are. So there are two star, two multiplication. So they are asked after first multiplication what will be the answer or what will be the top of the stack. So these are options. We will check how it operates. So this is a given is postfix expression. We have already seen that infix expression is operand operator and operand where the operator is in between two operands. Postfix expression is where the operator is at the post position. So first operands and then operators. So here we want to convert postfix operation to the infix operation. So here we will push the operands on the stack where infix to postfix we were pushing operators on the stack. So here our intention is to convert postfix to infix so we will push the operands on the stack. Now algorithm for this is read the symbol from the expression that is the input. Based on the input symbol go to the step 2 and 3. If the symbol is operand push on the stack. If the symbol is operator then pop top two values from the stack. These two popped values will be our operand. Now create a new string putting operator between two operands and then whatever the answer will be there again push it on to the stack and at the end only the value will remain in the stack which is infix expression. Now here we are having this expression 8 2 3 power slash 2 3 multiplication. So up to this we have to find the answer. Now here first 8 it is a operand scan symbol is operand so that will be pushed on the stack. Then 2 2 will be also on the stack 3 will be also on the stack all operand we are pushed on the stack. Then we are having the power. Now here power will be put on this immediate first two operands on the top of the stack. So here 2 raise to 3 so here output will be 2 raise to 3 will be 8 and that again pushed on the stack. So our stack will be 8 and 8. Now next we are having division so again we will pop 2 top of the stack 8 and 8 8 divided by 8 here it will be giving 1 and again we are pushing that on the stack. Now on the stack only 1 is there next we are having 2 we are pushed 2 on the stack then we are having 3 we are pushed 3 on the stack. Next to that we are having the multiplication so multiplication we are going to insert between this top 2 value so 2 into 3 that will be 6 that we are pushing on the stack. So top of the stack will be 6 and next will be 1. So here answer is top of the stack will be 6 and 1 so this is our final answer. Now next third find out the result after evaluating the postfic expression 10 phi u plus 66 divided by into 8 and minus. Now here again the same operation we will apply to this 10 that is operand we are pushing on the stack next phi u is operand we are pushing on the stack then we will apply this addition sign between 10 and phi u that will be 15 and that will be pushed on the stack. Then next we are having 60 that will be pushed on the stack then 6 is there 6 will be pushed on the stack then we are having the division sign. So that division will be 60 divided by 6 so where our answer is 60 divided by 6 is 10 so that will be pushed on the stack after that we are having the multiplication sign 15 into 10 that will be 150 that will be pushed on the stack. So next is 8 that will be pushed on the stack then we are having minus sign so 150 minus 8 that will be 142. So here we can find this option is 142 and this is the correct option that is 142. So here we are seen that postfix expression we are operating one more gate question we will be checking that the base data structure to check whether the arithmetic expression has balanced parenthesis for this operations are q, stack, tree and list. We can put every opening parenthesis in the stack and pop every time when we get the closed one. So at the end when we are having all the matching parenthesis opening and closing our stack will be empty and that empty stack is indicating that our parenthesis are balanced. So here we are using stack and that is the correct data structure for the checking arithmetic expression which are having the balanced parenthesis. Thank you.