When taking in a expression like (10+5*15) and following orders of operations.
How would one best solve a problem like this? What kind of data structure is best?
Thanks.
A formal structure for the organization of information. Examples of data structures include the list, queue, stack, and tree.
Not terribly much believe it or not. Algorithms and data structures is a very broad field. Obviously if you want to delve into some kinds of algorithms in particular, you need to know much more math.
An algorithm in math is a procedure, a description of a set of steps that can be used to solve a mathematical computation. For example, a step-by-step procedure used in long divisions is a common example of a mathematical algorithm.
I'd go with Dijkstra's Shunting yard algorithm to create the AST.
Try parsing the expression using recursive descent. This would give you a parse tree respecting order of operations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With