Infix to reverse polish using a stack

  Рет қаралды 65,497

HurrayBanana

HurrayBanana

Күн бұрын

Converting from infix to reverse polish (postfix) notation using a stack

Пікірлер: 89
@eltrasimaco
@eltrasimaco 10 жыл бұрын
Ive seen several tutorials here but this one is crystal clear
@HurrayBanana
@HurrayBanana 10 жыл бұрын
thanks, that's the idea
@T010RD
@T010RD 7 жыл бұрын
It's much clearer than virgin's teardrop
@computerkeen8210
@computerkeen8210 6 жыл бұрын
you made a 3 hour lecture in only 9 minutes, thats talent
@HurrayBanana
@HurrayBanana 6 жыл бұрын
That was the intention
@Wintotv
@Wintotv 7 жыл бұрын
love your english accent too xD i can't understand those Indian tutorials
@wakaboomnick
@wakaboomnick 11 жыл бұрын
Thank you, made it a lot easier than my teacher
@spyoox3978
@spyoox3978 8 жыл бұрын
hello
@sheilasubbiah5969
@sheilasubbiah5969 7 жыл бұрын
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.
@HurrayBanana
@HurrayBanana 7 жыл бұрын
glad it helped
@HurrayBanana
@HurrayBanana 7 жыл бұрын
Yeah, the left bracket sits on the stack so further operators can override whatever precedence was already on top.
@thebarnold7234
@thebarnold7234 2 жыл бұрын
I wish this was longer. Love the way you actually taught this.
@HurrayBanana
@HurrayBanana 2 жыл бұрын
Thanks, it's such a cool thing reverse polish
@tej_3423
@tej_3423 6 жыл бұрын
Thanks a lot! I'm taking part in CIE exams computer science tomorrow... you make it more easier
@JP-su9ib
@JP-su9ib 4 жыл бұрын
you"re such a charismatic, well explaining teatcher.
@HurrayBanana
@HurrayBanana 10 жыл бұрын
@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 +
@BarnabaRudge
@BarnabaRudge 9 жыл бұрын
For the good of humanity, such lectures should records and presents.
@OghmaNano
@OghmaNano Жыл бұрын
Really nice expiation, just implemented it in my semiconductor device model in C.
@HurrayBanana
@HurrayBanana Жыл бұрын
Nice
@josephburke7924
@josephburke7924 9 жыл бұрын
every year, when I have to teach RPN, I always end up watching this video. Cheers mate great vid :)
@HurrayBanana
@HurrayBanana 9 жыл бұрын
+Joseph Burke No problems, pity it's come out of the new specifcations. Favourite topic
@MrFacePeck
@MrFacePeck 5 жыл бұрын
Finally an understandable explanation of this. Thanks so much.
@HawksVideoNest
@HawksVideoNest 8 жыл бұрын
Well thank you :D Definitely saved me from failing an exam completely
@HurrayBanana
@HurrayBanana 8 жыл бұрын
glad to help
@Tr4vy
@Tr4vy 10 жыл бұрын
thanks for the "fack"ing help hehehe
@CaptainClueless01
@CaptainClueless01 8 жыл бұрын
Well now I can do reverse polish. Top notch!
@HurrayBanana
@HurrayBanana 8 жыл бұрын
+CaptainClueless Everyone should be able to do it, it's cool
@artsyishita8551
@artsyishita8551 6 жыл бұрын
Ohh thank you now i understood this concept....really helpful for my exams...thanks a lot...
@kombuchamp
@kombuchamp 4 жыл бұрын
Cheers, helped a lot to figure out an algorithm
@serhii_rudakov
@serhii_rudakov Жыл бұрын
amazing, Thank you for this great explanation
@MustafaOzanAlpay
@MustafaOzanAlpay 7 жыл бұрын
that video made everything crystal clear, and loved the accent hehe ^^ cheers mate!
@_Rohan007_
@_Rohan007_ 3 жыл бұрын
Thank you so much you explained it really well Sir
@Wintotv
@Wintotv 7 жыл бұрын
this just saved my life, thanks you so much Mr Banana =)
@HurrayBanana
@HurrayBanana 7 жыл бұрын
No problem, my favourite topic of all time :)
@James-se1rq
@James-se1rq 2 жыл бұрын
Lindy approved video!
@IDONTEATPANTS
@IDONTEATPANTS 8 жыл бұрын
Please be my professor. Also the FACK part made me lol
@laureven
@laureven 4 жыл бұрын
is always better to invest time for finding a good tutorial :) ...and Yours is Awesome :) ...search is over :)
@HurrayBanana
@HurrayBanana 4 жыл бұрын
Thanks
@rapramos5687
@rapramos5687 7 жыл бұрын
wow thank you so much! helped a lot!
@michaelholder5975
@michaelholder5975 10 жыл бұрын
What precedence would factorial "!" have. Does it go above exponents?
@Wyattap125
@Wyattap125 8 жыл бұрын
holy crap this was so helpful
@jakubputynkowski8554
@jakubputynkowski8554 8 жыл бұрын
great explaination :) thank you!
@HurrayBanana
@HurrayBanana 8 жыл бұрын
No problem, happy it was of some use
@einarstensson4323
@einarstensson4323 9 жыл бұрын
Thank you! Interesting.
@oguzkaraca1434
@oguzkaraca1434 7 жыл бұрын
did he just give an example over "fack up"?
@saifmohammed1481
@saifmohammed1481 4 жыл бұрын
"Facking" awesome !!
@СашаДискотека-л7й
@СашаДискотека-л7й 5 жыл бұрын
But how do you deal with expressions with the unary operator like: -A + B?
@HurrayBanana
@HurrayBanana 5 жыл бұрын
Higher priority than multiply and divide. Only Pop one item from stack like store does
@SnakeOilDev
@SnakeOilDev 7 жыл бұрын
purfect !
@appleraika
@appleraika 10 жыл бұрын
awesome!! thanks :)
@SuperJatinrajput
@SuperJatinrajput 9 жыл бұрын
great video sir, make up for bunk classes.
@HurrayBanana
@HurrayBanana 9 жыл бұрын
+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.
@XXxlightmarex
@XXxlightmarex 8 жыл бұрын
What do i do when i have multiple open brackets e.g. cos((a + b*c)/(d + e*(f-g^h))) ?
@HurrayBanana
@HurrayBanana 8 жыл бұрын
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
@HurrayBanana
@HurrayBanana 8 жыл бұрын
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
@XXxlightmarex
@XXxlightmarex 8 жыл бұрын
Thank you very much, you've been a great help
@jim93m
@jim93m 10 жыл бұрын
As easier as it gets :) thnx
@kidrahulable
@kidrahulable 7 жыл бұрын
Great job! Thank you very much for help! ;) No I understand it :D
@syntaxerorr
@syntaxerorr 3 жыл бұрын
I can't take it that the K is really an R
@samuelhor9700
@samuelhor9700 10 жыл бұрын
Any idea what order of precedence the trig functions sin, cos and tan fall under?
@michaelholder5975
@michaelholder5975 9 жыл бұрын
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 * +
@henryl3e
@henryl3e 10 жыл бұрын
would like to know what if there is a negative sign meet with a negative sign ? or any other sign meeting the same ones
@henryl3e
@henryl3e 10 жыл бұрын
for example pq-rs-/
@HurrayBanana
@HurrayBanana 10 жыл бұрын
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
@krzysztofwelc146
@krzysztofwelc146 5 жыл бұрын
God bless You
@s1nister688
@s1nister688 4 жыл бұрын
What happens when there is a modulus sign present?
@HurrayBanana
@HurrayBanana 4 жыл бұрын
Depends what the precedence for modulus is in that language
@LucasAlfare
@LucasAlfare 4 жыл бұрын
How to implement unaries using this?
@HurrayBanana
@HurrayBanana 4 жыл бұрын
Higher precedence than multiply and divide but lower than exponent
@Shotpl0xGaming
@Shotpl0xGaming 7 жыл бұрын
What happens whens 2 symbols hold the same line of precedence?
@HurrayBanana
@HurrayBanana 7 жыл бұрын
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)
@Shotpl0xGaming
@Shotpl0xGaming 7 жыл бұрын
I see, thank you very much for this. Helped me out heaps. Was just doing past papers, came across this scenario again.
@marcinpozniak1605
@marcinpozniak1605 2 жыл бұрын
6:32 why is the left bracket of higher precedence than the power of?
@HurrayBanana
@HurrayBanana 2 жыл бұрын
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
@marcinpozniak1605
@marcinpozniak1605 2 жыл бұрын
@@HurrayBanana okay, the drawing in the top right corner misled me. thank you
@HurrayBanana
@HurrayBanana 2 жыл бұрын
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
@mdy405
@mdy405 10 жыл бұрын
why did you pop "*" before you push "/" if they are the same priority??? i dont really understand this!!
@HurrayBanana
@HurrayBanana 10 жыл бұрын
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
@mdy405
@mdy405 10 жыл бұрын
HurrayBanana Thank you !
@bryanarp19
@bryanarp19 3 жыл бұрын
Saludos a la BUAP xd
@JoffreyB
@JoffreyB 6 жыл бұрын
somebody add please subtitles
@saranshdhyani3164
@saranshdhyani3164 6 жыл бұрын
Where is code?
@HurrayBanana
@HurrayBanana 6 жыл бұрын
saransh dhyani this process described here is reasonably easy to code up if you parse the expression first to tokenise each component
@messi-ih4uy
@messi-ih4uy 6 жыл бұрын
keke do you love me
@kiranrambha
@kiranrambha 10 жыл бұрын
plus cannot be placed on plus minus cannot be placed on minus right?????
Evaluating reverse polish using a stack
4:11
HurrayBanana
Рет қаралды 16 М.
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 12 МЛН
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН
Reverse Polish Notation and The Stack - Computerphile
13:32
Computerphile
Рет қаралды 308 М.
Reverse Polish Notation Using Stacks
16:57
Erb Computer Science
Рет қаралды 30 М.
Infix to Postfix using stack
18:20
mycodeschool
Рет қаралды 756 М.
Comp Sci in 5: Shunting Yard Algorithm
5:55
Comp Sci in 5
Рет қаралды 32 М.
Infix, Prefix and Postfix
13:38
mycodeschool
Рет қаралды 932 М.
Comp Sci in 5: Post Fix Stack Evaluator
3:47
Comp Sci in 5
Рет қаралды 7 М.
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 12 МЛН