You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Shunting Yard Algorithm video, we give + a higher precedence than -. Whilst this is usually fine, there's an issue here.
Consider the expression 1 - 2 + 3. Mathematically, if we were to add then subtract, what we want to be doing is -2 + 3. What the code does in this case instead is 2 + 3. This means that we end up doing 1 - 5, rather than 1 + 1, which is incorrect.
The easiest solution would be to give + and - the same precedence, and for the sake of consistency also give * and / the same precedence. Alternatively we'd need to check whether the first parameter is part of a subtraction, which can be a little finnicky.
The text was updated successfully, but these errors were encountered:
I noticed this also...but I have a different explaination of how it should be:1-2+3 if + and - are the same precedence level which is consistent with what I was taught but not the video.evualating left to right I get1-2 = -1then -1+3 = 2 again.
interested in Javid's view.
On Sunday, May 5, 2024 at 10:13:50 AM CDT, Krystal Hallett ***@***.***> wrote:
In the Shunting Yard Algorithm video, we give + a higher precedence than -. Whilst this is usually fine, there's an issue here.
Consider the expression 1 - 2 + 3. Mathematically, if we were to add then subtract, what we want to be doing is -2 + 3. What the code does in this case instead is 2 + 3. This means that we end up doing 1 - 5, rather than 1 + 1, which is incorrect.
The easiest solution would be to give + and - the same precedence, and for the sake of consistency also give * and / the same precedence. Alternatively we'd need to check whether the first parameter is part of a subtraction, which can be a little finnicky.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
In the Shunting Yard Algorithm video, we give + a higher precedence than -. Whilst this is usually fine, there's an issue here.
Consider the expression 1 - 2 + 3. Mathematically, if we were to add then subtract, what we want to be doing is -2 + 3. What the code does in this case instead is 2 + 3. This means that we end up doing 1 - 5, rather than 1 + 1, which is incorrect.
The easiest solution would be to give + and - the same precedence, and for the sake of consistency also give * and / the same precedence. Alternatively we'd need to check whether the first parameter is part of a subtraction, which can be a little finnicky.
The text was updated successfully, but these errors were encountered: