 Welcome to the session data structure stack gate questions. The learning outcome is at the end of this session the student will be able to solve data structure stack problems. Pause the video and find out the answer. For this question only we are using two knowledge of first days of stack and second days of cube. What is the stack? Stack is having two basic operations where we are inserting and deleting the any variables. Here we are calling that as push which insert a data atom on the stack and pop which removes an atom from the top of the stack. So when we are pushing any atom then second we are pushing. So whatever the data will be on that top of the stack and when we are removing it immediately whatever top of the stack that will be going to remove. So that will be last in first out. So first in first out that is the wrong answer. Second for the cube we will see cube is having concept that whatever the elements we can access in the cube is in the first in first out manner. That is whatever we are entering data first that will be coming out first. So as we can see this last in first out type of the computations are efficiently supported by cube is wrong answer because it is a last in first out is not the correct answer but it is a first in first out. So first and fourth both are wrong answer wherever the first and fourth is mentioned so all three options are wrong so only the A that is the correct answer. Now next question is the following operations are performed on a stack push 10 push 20 pop push 10 push 20 pop pop pop push 20 pop. The sequence of the values popped out will be this is the question of 1991 this also you can try to answer it. So we will see the sequence first we are going to push 10 so in this sequence we are pushing 10 then we are pushing 20 and then immediately we are popping that 20. Then next we are pushing 10 then pushing 20 then popping means 20 10 and 10 so three pops will be there and then next we are pushing 20 and immediately we are popping it. So last will be 20 so our sequence will be 20 20 10 10 20 so this answer is matching here 20 20 10 10 20. So here B answer is matching over here. Now this is the third question assume that the operator plus minus multiplication are left associative and power is the right associative. The order of precedence from highest to lowest is power multiplication addition and minus. The postfix expression corresponding to the infix expression A plus B into C minus D raise to E raise to F will be what will be the answer for this. So this is the infix operation it is given and we have to find out what will be the postfix operation matching to this operation. So this question is of 2004 so basically we will see what is the infix expression. Here infix expression means when the operator is between two operand that is operand operator and operand if it is in this sequence then it is called as a infix expression. So your operator is infix. So for example it is A plus B what is the postfix expression? Postfix expression is when your operator is at the post place means operand and operand and then operator is there. At the end if all the operators are there then it is called as a postfix expression. Now in given question we have to convert infix expression to postfix expression. Now in that case we will be using stack and we will be pushing all the operators on the stack. So when converting infix to postfix the stack will push all the operator on the stack. And reverse case when we are converting postfix to infix with the stack we have to push operands instead of operators here. Now we will see the algorithm how to convert infix to postfix. So first push here first we are pushing opening bracket and we are ending with closing bracket. So our stack will show first pushing of opening bracket then we will scan here we have mentioned x and y. x is the infix expression and y is postfix expression what will be converted after the conversion. So here let x is the arithmetic expression written in infix notation the algorithm will find the equivalent of this postfix expression y. And we will be scanning it from left to right and then repeat the steps 3 to 6 for each element in the x until the stack is empty. Now what is the main operations will be here if an operand is encountered add directly to the y. y means postfix expression if we are finding any operand then that operand will go to directly y. If a left parenthesis is encountered we will be pushing it on the stack. If an operator is encountered then repeatedly we will be popping from the stack and add to y each operator. Which is the same precedence or higher precedence? Now means we will be popping any operator when it is having the same precedence or higher precedence than the operator. Then one more condition will be there that if a right parenthesis is encountered. Since here we have pushed a left parenthesis and if we find the right parenthesis then we will be repeatedly popping all the stack. And add to the y each operator from the top of the stack until we are finding left parenthesis on the stack. And then we will be removing that left parenthesis from the stack. So this is the algorithm to convert mainly two operations are there we are pushing the operator on the stack. And when we are popping it when we are finding the same precedence or higher precedence then whatever we are scanning that operator. So your gate quotient is 3 which is given a plus b into c minus d power to e power to f. Now here first we will push this curly bracket then we are having a. A will be directly going to the post peak expression then plus is there after that plus. We are pushing that on the stack b is there b will be go to the post peak expression then multiplication sign is there. Multiplication sign is higher precedence than this addition so it will be pushed on the stack. Then we are having c so here a b c will be there and then we are having scan sign is minus. Now minus sign is smaller precedence than whatever we are having in the stack. So we are popping this multiplication sign as well as addition sign. So here you can see that multiplication sign and addition sign will be popped. Now next after that is d d is pushed then d is added to the post fix expression then power sign is there. Power will be the higher precedence so we are pushing to the stack and then e is there so that will go to the post fix expression. Then again we are having power so here power and power sign will be the same precedence. So whatever in the stack and already we have scan so both will be having same precedence. Here we need to pop actually but this second power sign is right associative as it is right associative. So we are pushing that in the sequence and we are not popping anything then we are putting e is already there and then f. After that whatever the top of the stack that will be popped so both power will be popped and lastly minus n. So our expression a plus b into c minus d power to e power to f will be converted a b c multiplication plus d e f power to power to minus. So there one more question is there which of the following is essential for converting an in fix expression to post fix form efficiently. So options are an operator stack, an operand stack, an operand stack and operator stack a pastry. So just we have seen that we need a operator on the stack so we have to push operators on the stack so that is the correct answer. Thank you.