The Shunting Yard Algorithm Demystified: Transform Expressions Like a Pro!

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 มี.ค. 2024
  • Welcome to my in-depth tutorial on the Shunting Yard Algorithm! 🚂💻 In this video, I unpack and explain this intriguing and useful algorithm. Designed by Edsger Dijkstra, this algorithm is a cornerstone for understanding expression evaluation and conversion, as it converts infix expressions to postfix (or Reverse Polish Notation) expressions.
    ---
    Source code: github.com/garyexplains/examp...
    Twitter: / garyexplains
    #garyexplains
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 30

  • @tommurphy7157
    @tommurphy7157 4 หลายเดือนก่อน +1

    Brilliantly explained and very timely! Just what I needed to create the 'advanced' search for my app

  • @bendono
    @bendono 4 หลายเดือนก่อน +3

    I used RPN on my HP48G calculator while in high school. I also learned the Shunting Yard algorithm in my Computer Science degree; however, I guess I never really understood what "shunting yard" meant. It seems to be the British expression for a rail yard. I don't think it is a common term in US English. I recall classmates jokingly interpret it as "shatting yard" as in a place to to take shit.

  • @nickeax
    @nickeax หลายเดือนก่อน

    Thank you for the great presentation.

  • @muddyexport5639
    @muddyexport5639 4 หลายเดือนก่อน +2

    Excellent explanation and demo.

    • @GaryExplains
      @GaryExplains  4 หลายเดือนก่อน

      Glad you liked it!

  • @user-jv1js9oc8l
    @user-jv1js9oc8l 3 หลายเดือนก่อน

    This was perfect timing thank you!

  • @Garythefireman66
    @Garythefireman66 4 หลายเดือนก่อน

    Thanks professor! 🤓

    • @GaryExplains
      @GaryExplains  4 หลายเดือนก่อน

      My pleasure!

  • @alejandroguardiola9085
    @alejandroguardiola9085 2 หลายเดือนก่อน

    Great video, but I have a question, in the explanation it seems like the output is a queue instead of a stack?

  • @bertblankenstein3738
    @bertblankenstein3738 4 หลายเดือนก่อน

    Once upon a time I coded a stack and the operators were numbers in an array of pointers to functions. I was kind of hoping to learn how this relates to railyards tho.

  • @kenc4026
    @kenc4026 2 หลายเดือนก่อน

    Great work, sir. I got an idea because of this. Does this logic applies to Boolean Algebra too?

    • @cxrbon637
      @cxrbon637 2 หลายเดือนก่อน

      i think so

  • @AlwaysCensored-xp1be
    @AlwaysCensored-xp1be 4 หลายเดือนก่อน

    I wonder if LLM can solve those model train shunting games?

  • @berjancemdarc4345
    @berjancemdarc4345 หลายเดือนก่อน

    What would this code do on situations like 10+2 ?

    • @Lumelore
      @Lumelore 13 วันที่ผ่านมา

      When it parses the input it uses space as a delimiter, so 10 would be interpreted as 10 but 1 0 would be two separate entries. In the stack, 10 is stored as a single element and not multiple separate ones for each digit.

  • @HyyskanPolttaja
    @HyyskanPolttaja 4 หลายเดือนก่อน

    Great! But what about square roots & stuff?

    • @GaryExplains
      @GaryExplains  4 หลายเดือนก่อน +1

      For other operations you would use functions like cos (), sqrt(), etc. This is how you could write a compiler or interpreter using this method. It is the same principle. Functions have a lower precedence than plus and minus. Raise-to-power ^ has the highest precedence.

  • @uvatham
    @uvatham 4 หลายเดือนก่อน +1

    00:06

  • @CanadianBakin42O
    @CanadianBakin42O 4 หลายเดือนก่อน

    FÍRST!

  • @sssyt4837
    @sssyt4837 4 หลายเดือนก่อน

    First!

  • @K9-33
    @K9-33 4 หลายเดือนก่อน

    Just use the FORTH programming language.

    • @GaryExplains
      @GaryExplains  4 หลายเดือนก่อน

      That isn't the point. The point is to know how to do it yourself.

  • @LA-MJ
    @LA-MJ 3 หลายเดือนก่อน

    Exit takes an exit code not a calculation result 😂

    • @GaryExplains
      @GaryExplains  3 หลายเดือนก่อน

      And why can't the exit code be a calculation result?

    • @LA-MJ
      @LA-MJ 3 หลายเดือนก่อน

      @@GaryExplainsbecause non-zero exit code means error occurred in standard semantics

    • @GaryExplains
      @GaryExplains  3 หลายเดือนก่อน

      No, not necessarily. If you want a program to calculate something it can return the calculation as an exit code. This is very useful for scripting. You are making an assumption about the return codes, I assume based on Unix/Linux. On VMS for example SUCCESS was never 0.

    • @LA-MJ
      @LA-MJ 3 หลายเดือนก่อน

      @@GaryExplainsof course it's UNIX. Which matters more