Converting from infix to reverse polish (postfix) notation using a stack
Пікірлер: 89
@eltrasimaco10 жыл бұрын
Ive seen several tutorials here but this one is crystal clear
@HurrayBanana10 жыл бұрын
thanks, that's the idea
@T010RD7 жыл бұрын
It's much clearer than virgin's teardrop
@computerkeen82106 жыл бұрын
you made a 3 hour lecture in only 9 minutes, thats talent
@HurrayBanana6 жыл бұрын
That was the intention
@Wintotv7 жыл бұрын
love your english accent too xD i can't understand those Indian tutorials
@wakaboomnick11 жыл бұрын
Thank you, made it a lot easier than my teacher
@spyoox39788 жыл бұрын
hello
@sheilasubbiah59697 жыл бұрын
I had the same question as the student in the video about the left bracket which goes on the stack, but I think I understand now; basically the left bracket 'has a precedence' which other operators compare their own precedence against, but the left bracket ignores its own precedence (i.e. never compares its own precedence against any of the operators (even though it could)) and just goes to sit on top of the stack. Thanks for your great example, with an assignment and other tricky bits! It's really helped me.
@HurrayBanana7 жыл бұрын
glad it helped
@HurrayBanana7 жыл бұрын
Yeah, the left bracket sits on the stack so further operators can override whatever precedence was already on top.
@thebarnold72342 жыл бұрын
I wish this was longer. Love the way you actually taught this.
@HurrayBanana2 жыл бұрын
Thanks, it's such a cool thing reverse polish
@tej_34236 жыл бұрын
Thanks a lot! I'm taking part in CIE exams computer science tomorrow... you make it more easier
@JP-su9ib4 жыл бұрын
you"re such a charismatic, well explaining teatcher.
@HurrayBanana10 жыл бұрын
@kiran, your thinking is correct, because they are the same precedence, need to remove from stack (doesn't really matter with + on + or - on -) but is for + on - or - on +
@BarnabaRudge9 жыл бұрын
For the good of humanity, such lectures should records and presents.
@OghmaNano Жыл бұрын
Really nice expiation, just implemented it in my semiconductor device model in C.
@HurrayBanana Жыл бұрын
Nice
@josephburke79249 жыл бұрын
every year, when I have to teach RPN, I always end up watching this video. Cheers mate great vid :)
@HurrayBanana9 жыл бұрын
+Joseph Burke No problems, pity it's come out of the new specifcations. Favourite topic
@MrFacePeck5 жыл бұрын
Finally an understandable explanation of this. Thanks so much.
@HawksVideoNest8 жыл бұрын
Well thank you :D Definitely saved me from failing an exam completely
@HurrayBanana8 жыл бұрын
glad to help
@Tr4vy10 жыл бұрын
thanks for the "fack"ing help hehehe
@CaptainClueless018 жыл бұрын
Well now I can do reverse polish. Top notch!
@HurrayBanana8 жыл бұрын
+CaptainClueless Everyone should be able to do it, it's cool
@artsyishita85516 жыл бұрын
Ohh thank you now i understood this concept....really helpful for my exams...thanks a lot...
@kombuchamp4 жыл бұрын
Cheers, helped a lot to figure out an algorithm
@serhii_rudakov Жыл бұрын
amazing, Thank you for this great explanation
@MustafaOzanAlpay7 жыл бұрын
that video made everything crystal clear, and loved the accent hehe ^^ cheers mate!
@_Rohan007_3 жыл бұрын
Thank you so much you explained it really well Sir
@Wintotv7 жыл бұрын
this just saved my life, thanks you so much Mr Banana =)
@HurrayBanana7 жыл бұрын
No problem, my favourite topic of all time :)
@James-se1rq2 жыл бұрын
Lindy approved video!
@IDONTEATPANTS8 жыл бұрын
Please be my professor. Also the FACK part made me lol
@laureven4 жыл бұрын
is always better to invest time for finding a good tutorial :) ...and Yours is Awesome :) ...search is over :)
@HurrayBanana4 жыл бұрын
Thanks
@rapramos56877 жыл бұрын
wow thank you so much! helped a lot!
@michaelholder597510 жыл бұрын
What precedence would factorial "!" have. Does it go above exponents?
@Wyattap1258 жыл бұрын
holy crap this was so helpful
@jakubputynkowski85548 жыл бұрын
great explaination :) thank you!
@HurrayBanana8 жыл бұрын
No problem, happy it was of some use
@einarstensson43239 жыл бұрын
Thank you! Interesting.
@oguzkaraca14347 жыл бұрын
did he just give an example over "fack up"?
@saifmohammed14814 жыл бұрын
"Facking" awesome !!
@СашаДискотека-л7й5 жыл бұрын
But how do you deal with expressions with the unary operator like: -A + B?
@HurrayBanana5 жыл бұрын
Higher priority than multiply and divide. Only Pop one item from stack like store does
@SnakeOilDev7 жыл бұрын
purfect !
@appleraika10 жыл бұрын
awesome!! thanks :)
@SuperJatinrajput9 жыл бұрын
great video sir, make up for bunk classes.
@HurrayBanana9 жыл бұрын
+Jatin Rajput To be fair nothing makes up for bunk'd classes, it's amazing the nuances and added extra's you'll get when someone goes through a topic with you. I always find that I talk about things I never planned.
@XXxlightmarex8 жыл бұрын
What do i do when i have multiple open brackets e.g. cos((a + b*c)/(d + e*(f-g^h))) ?
@HurrayBanana8 жыл бұрын
XXxlightmarex just keep applying the rules. every left bracket goes on top of stack. when you get a right bracket remove contents of stack untill you find a left bracket, then discard that snd continue to parse the expression
@HurrayBanana8 жыл бұрын
work through remember operands just get written down as rpn (don't involve the stack at all) ((a + b * c) / (d + e * (f - g ^ h))) reaching first right bracket stack contains * + ( ( remove up to topmost left bracket and discard giving: abc*+ stack only contains ( carrying on until we reach 2nd right bracket, stack should contain: ^ - ( * + ( / ( dump stack upto topmost left bracket and discard giving us this much of the rpn: abc*+defgh^- stack now contains * + ( / ( parse 3rd right bracket so remove stack contents again upto topmost left bracket giving rpn of: abc*+defgh^-*+ stack contains / ( process final right bracket by removing upto topmost left bracket giving rpn of: abc*+defgh^-*+/ stack now empty hope this helps
@XXxlightmarex8 жыл бұрын
Thank you very much, you've been a great help
@jim93m10 жыл бұрын
As easier as it gets :) thnx
@kidrahulable7 жыл бұрын
Great job! Thank you very much for help! ;) No I understand it :D
@syntaxerorr3 жыл бұрын
I can't take it that the K is really an R
@samuelhor970010 жыл бұрын
Any idea what order of precedence the trig functions sin, cos and tan fall under?
@michaelholder59759 жыл бұрын
Trigonometric functions, or functions in general, go above exponents. For example: 2 + 3^4 * cos(0) Steps: 1. 2 is an operand; Add 2 to the output expression 2. + is an operator; Stack = empty; push + onto the stack 3. 3 is an operand; Add 3 to the output expression 4. ^ is an operator; Top of stack has lower precedence; push ^ onto stack 5. 4 is an operand; Add 4 to the output expression 6. * is an operator; Top of stack has higher precedence; pop stack until lower precedence is found; push * onto stack 7. cos is treated as an operator; top of stack has lower precedence; push cos onto stack 8. "(" = push onto stack regardless of lower or higher precedence or stack is empty 9. 0 is an operand; Add 0 to output expression 10. ")" = Pop and add to output expression until "(" = top of stack; pop top of stack 11. Since ")" is the end of the expression, pop the stack until stack = empty Result: 2 3 4 ^ 0 cos * +
@henryl3e10 жыл бұрын
would like to know what if there is a negative sign meet with a negative sign ? or any other sign meeting the same ones
@henryl3e10 жыл бұрын
for example pq-rs-/
@HurrayBanana10 жыл бұрын
WooHoooP Don't understand your example that would come from the infix (p - q) / (r - s) But to answer your question: if you have an expression of this form a - - b the minus in front of the b is actually unary minus (negation, applied to one operand) we would re-write that expression like this a - ~ b (using tilda to represent the unary minus) this would generate as unary minus is higher precedence that + or minus. a b ~ - which would negate the b before attempting to subtract it from a, which is logical in this example The precedence of unary minus is open to debate in some environments its placed higher than exponent (raising to the power ^) but others may place it below this but above multiply and divide. ~ b ^ a if unary minus was higher we would get b ~ a ^ which would negate b then raise to the power of a, but some would argue that we should have exponent higher than unary minus meaning this b a ^ ~ which would raise the b to the power of a and negate the result
@krzysztofwelc1465 жыл бұрын
God bless You
@s1nister6884 жыл бұрын
What happens when there is a modulus sign present?
@HurrayBanana4 жыл бұрын
Depends what the precedence for modulus is in that language
@LucasAlfare4 жыл бұрын
How to implement unaries using this?
@HurrayBanana4 жыл бұрын
Higher precedence than multiply and divide but lower than exponent
@Shotpl0xGaming7 жыл бұрын
What happens whens 2 symbols hold the same line of precedence?
@HurrayBanana7 жыл бұрын
Another burgermate you can only place an operator on top if it is higher so remove the item on top of stack snd write it down in the rp expression, then see if the new operator can now go on the stack (like normal)
@Shotpl0xGaming7 жыл бұрын
I see, thank you very much for this. Helped me out heaps. Was just doing past papers, came across this scenario again.
@marcinpozniak16052 жыл бұрын
6:32 why is the left bracket of higher precedence than the power of?
@HurrayBanana2 жыл бұрын
Left brackets are always going to override precedence, it goes on top of everything, it's also there as a marker for when we encounter a right bracket while parsing, so we know when to stop pulling operators off the stack
@marcinpozniak16052 жыл бұрын
@@HurrayBanana okay, the drawing in the top right corner misled me. thank you
@HurrayBanana2 жыл бұрын
The diagram shows that all operators go on top of left bracket if it seen on top of the stack. Parsing a left bracket in the expression doesn't look at precedence as you automatically push it onto the stack
@mdy40510 жыл бұрын
why did you pop "*" before you push "/" if they are the same priority??? i dont really understand this!!
@HurrayBanana10 жыл бұрын
You can only push onto the stack if the precedence is higher, if it is the same you must pop the stack until the operator is higher than the contents of the top
@mdy40510 жыл бұрын
HurrayBanana Thank you !
@bryanarp193 жыл бұрын
Saludos a la BUAP xd
@JoffreyB6 жыл бұрын
somebody add please subtitles
@saranshdhyani31646 жыл бұрын
Where is code?
@HurrayBanana6 жыл бұрын
saransh dhyani this process described here is reasonably easy to code up if you parse the expression first to tokenise each component
@messi-ih4uy6 жыл бұрын
keke do you love me
@kiranrambha10 жыл бұрын
plus cannot be placed on plus minus cannot be placed on minus right?????