STACK APPLICATION : EXAMPLES FOR CONVERTING INFIX TO POSTFIX EXPRESSION - DATA STRUCTURES

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi friends welcome to our Channel so in the previous session we have seen the algorithm for converting the infix expression to postfix expression so also we have seen what is meant by fix prefix and postfix so in this session we'll solve some examples so that you no doubt will be clarified so I take hands let us see the algorithm so there will be an infix expression so we have to read it as a string and then we have to maintain one stack and we have to maintain on postfix expression so we have to read each and every character from the in fix expression so if it is a left parenthesis then simply we can place that left parenthesis into the stack if it is if the reading character is an operand simply place that operand in to the postfix expression if the reading character is an operator we have to place that operator into this tank so here one thing to be remembered that is our stack consists of only the operators so if the reading character is an operator first we have to check whether the stack is empty or not so if the stack is empty simply we can push that operator into the stack if stack is not empty we have to check the priority of the operators which is available in the stack and which is reading but from the in fix expression right here if the reading character that means a reading operator priority is greater than the top of the stack priority I mean the operator available at the top of the stack then simply we can push the operator into the stack and the second case if the priority of the operator which we are reading from the in fix is less than the operator available at the top of the stack simply we have to pop the operator from the stack and pushed it to the postfix expression and then we have to again check with check this priorities with second I mean second top of the stack Edmund right so after this process if the character is a right parenthesis then simply we can remove or pop all the elements all the operators available in the stack until you reach just the left parenthesis and place them into the postfix expression right so if the complete reading of all the characters from the in fixed expression is completed and still the stack is not empty then simply pop all the operators from the stack and place it in the postfix expression right so this we have seen in previous session so I will just post the link in the description section so that you can once go through that and then you can listen it so here in today's session we will solve a few examples so how to convert these infix to postfix based upon our algorithm infix to postfix expression example so let us take this example so how to convert this infants so this is the infix okay so this is the in fixed expression now we have to convert this in fixed expression to postfix expression right see so this is the character which we are reading so this is the stack for placing the operators and this is the post fix expression postfix expression right first yay-yay is a character right so we know that we know that if it is a operand simply place it in the post feels so empty step and a is placed it here next minus minus is the operator so if it is an operator first we have to check for the empty step so it is empty so directly we can push there - so see - right then simply post which expression consists of only and next parenthesis left appearances so simply we can push into the stamp simply we can push it to the stack so - left appearances right the postfix expression is here next be B so B is M or bread so simply we can add to the postfix so B and here the stack is same there is no difference in step and here it will be a star star so it is an operator so first we have to check whether star the priority of star is highest then the top of the stack operator so here the top of the stack if the the stack is with the parentheses some appearances simply we can push the operator understand so we need not check for the priority simply we can push the operator so after pushing the operator see - paralysis 3 so here there is no change a b c so c is an operator source we have to push into the postfix so there is no change in the stack - references and star a b c thank then again - - so here stack is not empty so we have to check the priority so priority of the reading operator that is - is less than the top of the stack operator is star of the stack operator is stamp so the priority of - is less then a priority of star so we cannot push this - on to the stack because of the entrant is having the highest priority so remove the element of further stack and place it on the postfix expression so and then follow the same procedure so no see - paralysis and we have removed the star so a b c star and we have to check for the same condition for the next term somehow copies left balances so left balances we have no no the condition if it is but I just simply we can push the operator to the top of the stack so - can't be pushed here hope you understood right so star is having the highest priority we can't move this - that is this - Oh operator on to the star so we have to remove this time and we have to place it on the postfix then we have to apply the same procedure for the next step of next operator so the here the next operator is left appearances so there is no constraint for the left paralysis so we can simply push the elements onto the stack if it is if the top of the stack is left parents so the quietness next D there is no change in step so ABC star okay see after be there is it close the parentheses okay there's a closer parents so now see closing parenthesis means what we have to do so we have to pop all the elements of the stack until it reaches the left upper axis and place it on the postfix expression right no see so let us take this tag here let us take this tank here so marinus and so we have to pop this one above the minus here and the next two left parenthesis here so we let's not write the references I write parents it's all the postfix expression so we have to remove all of the elements of the stack until it reaches the left parenthesis all you wonder if it is there so we have done right next divided by David anybody so / / is greater than the priority of / is greater than the priority of - so we can simply push this / on to the step - then e e so easy he is an operand so simply we can write it here so there is no change in state - and / so a B C star D minus P now we have completed reading all the characters of him fix expression right so if even though the stack is not a D so we can pop anything so the postfix expression ABC star B - E open so top of the head next slot so this one is the postfix expression for this right this one is the postfix expression for this given in fixed expression so hope you understood right we have to meet every character and based upon the character and vegetable the priority we have to place that operator in the step and we have to pop the operator in the stack and we have to place it in their postfix expression so hope you understood all these things right all right so let us solve one more example so just based upon the algorithm follow the instructions only will constrain test give the stack consists of four left appearances then simply we can push the operator on to the left branches there is no constraints okay now so let us take a one more example and then we will solve it right yeah divided by B minus into him - a okay hey little latch so I will not write a line by then just we will go with a simple process okay so try to understand so let us consider a stack so let us consider this time let us consider post piece so this is the stack this is the post so we are reading the characters one by one so first one is left parenthesis so simply we can push it in the step right then yeah this is an opera okay this is an opera so simply we can push in the post view so yeah is here / so / is the operator we have to check the priority here it is a references so there is no read of checking the priorities so simply we can use / / here okay and the postfix expression is no change that is yay next again open finances so open finances is also having no constraint so we can simply push it into the okay then B it is a operate I mean operate so simply we can place it in the postfix expression next - - so here the top of the stack is closed I've been open paranthesis left parents's so we can simply pushed it - here result there is no change in post please next operant C so this is an operand so we can simply place the see here post fix expression next operator plus operator place so here the stack is oddity so we have to check with the top of the set priority the priority of Plus and priority of violence both are equal so that's why even in such case also we have to remove the element from the stack and then it should be added to the postfix expression and then we have to check the condition further right so here both are having the same right hand in plus and minus are having the same rank so we have to prompt this - and we have to place here and then now top of the stack is left balances again check the condition so it is a tough viruses there is no condition we can simply push it into the stack right so - is placed in the postfix expression next D it is an operand simply we can write here next closing parenthesis close appearances so if it is a closing parenthesis we have to remove all the elements or into it from the stack until it reaches them close our parentheses open parenthesis right left parenthesis so here until the left where and since there is only one element so pop this element and place it here and remove the clopin a left parenthesis here okay so we not not know we need not place the left hand by appearances on the couch inscription right and again again the white balances again do the same process so here there is only one operator that is division operator until it reaches the right parenthesis right so left parenthesis so remove this and remove this and place it here okay now stop stop so simply place start the step because it's tag is empty here you go stack is empty simply we need to go check for the priorities directly we can place this down in the stand and again left parenthesis so simply left appearances doesn't need to check the priority so simply push on the push onto the stand next e e is an operand so directly we can write it in the postfix expression - so we have to place this - into the so before placing we have to check for the priority so here the top of the stack is left appearances so we need to check for the priority simply we can place I mean we can push the minus operator into the stack right then yay yeah he's an operative operand so simply we can write a in the postfix expression and close appearances closer balances again the same rule so we have to pop all the elements from the stack until it reaches the left appearances and place them into the postfix expressions here is there is only one operator that is a minus of minus operator so you just a remove a minus operator and place it here and star and instant so here also the resistance so star and star both are having the same priority even though they are having the same priority we have to pump the element from the stack and press place it in the postfix expression so remove this star and place it here and they it is a star I mean none of the stack is empty so star is placed here okay now see see is it a brand so seriously here so we have completed reading all the characters from the in fix expression but still stack is order B so we have to pop all the elements from the stack and place it in the postfix expressions so this one is the postfix expression so this is the stack okay so this is the postfix expression for the given in fixed expression so hope you understood this one right so simply following the algorithm so before solving these problems so just to go through the algorithm so that your dog should be clear right so shall we do one more example see let us do one more example and we'll find out see ya divided by B minus C plus B star e minus a star C C so this is an English expression so now we have to convert it to the postfix expression so let us take a take a stack here so let us take his tag here and let us take the postfix expression here so first read the character okay so this is the post pics yeah so yeah he's an operand so directly we can place it in the postfix expression next divided here stack is empty so still little bit will be placed in the step next third characteristic is an operand so simply place it in the first place next operator - so here the stack is not empty so we need to check the priority for the operator so priority of - is less than the priority of division so that is why first we have to form this operator from the stack and place it in the buzzfeed expression and again we have to check with the next to top of the side but here the stop you know after removing the operator division here the stack is empty so that's why simply we can place the minus here itself next to C so C is an operand you can play C here and plus so plus and minus so both are having the same priority even though the both are having the same priority we know to pump the element from the span and place it in the booth fritz and again repeat the process with this next operators but after removing the - the stack is again empty so simply we can push the plus operator into the stack next to D so there is a operand so simple we can be here next stop so star is a multiplication operator which is having the highest priority than the press but so priority of multiplication operator is greater than the priority of addition operator so simply we can push that but we know operator into the stack all right so if it is so if the priority is less then we can't push the operator it so here the priority of fan is higher then the priority of less so we can push this time to the stand right next so he is an operand so simply we can write it in the postfix expression next - see here such case so - and star top of the stack is star here reading characters - so the parameter - is less than the priority of star so we cannot push the - on above to the star operator so that is why here we have to bomb this and place it in the post postfix and check with this one - plus so now top of the stack is pressed again we have to check with the top of the stack - plus again both are having the same priority even though the has the same priority remove the element from the stack and place it in the postfix expression and again to put the same consistent so after removing the place after remove the place the stack is empty so we can simply move this - it will appear next a.n.jell operand so simply we can write 8 here and again strung so star is having the highest priority there - so simply we can push the start here okay next to see see is an operand so C can be written directly in the postfix expression see this is a C okay then we have completed reading all the characters from the infix expression so still the stack is not until no all the elements from the stack and place it in the postfix expression first pop star place it in the post wings then pop - place it in the postfix okay so this is the postfix expression for the given in fixed expression so we have to read all the characters and based upon the priority precedence and we have to push the elements into the stack or not okay so hope you understood these sessions a very simple thing so I will post the I mean copy the link of this algorithm in the description section so go through that description section go through that particular link and then you can solve this one right so if you really understood my session like my sessions and if you are having any doubts dividing this session feel free to post your doubts in the comment section so that I will definitely try to clarify all your doubts and share my sessions with your friends and don't forget to subscribe to our Channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 74,185
Rating: undefined out of 5
Keywords: sundeep, saradhi, kanthety, data structures, fundamentals, basics, arrays, lists, linked lists, stacks, trees, graphs, insertion, deletion, primitive, non primitive, linear, non linear, stacks using arrays, push, pop, top of stack, stack full, stack empty, LIFO, LAST IN FIRST OUT, dynamic memory, malloc, free, stack using linked lists, INFIX, POSTFIX, PREFIX, EXPRESSION, ALGORITHM, PROGRAM, EXAMPLE, CONVERSION, STACK APPLICATIONS, OPERATOR, OPERAND, ARITHMETIC EXPRESSION, SYMBOLS, CHARACTERS
Id: GECyceDg2bg
Channel Id: undefined
Length: 24min 17sec (1457 seconds)
Published: Fri Jun 21 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.