I am looking all over internet to find a logic to convert an Algebraic Expression into a Binary Tree.

I could only find ones where you first convert the algebra expression to postfix or prefix and then convert it to Binary Tree.

I am just curious to know , if its possible.

Any pointers to external links or logical answers to put me in the right direction ?

yes A Syntax Tree

So this expression


should be translated into

              |     |
    |---(*)---|     |---(*)---|
    |         |     |         |
|---(+)---|   D     E         F
|         |
|         |
A   |--( - )--|
    |         |
    B          C
  • There are dozens of algorithms for that (virtually everything labeled "parsing" that's more powerful than finite automata), and the algorithms for converting to postfix or prefix can most likely be adapted. – user7043 Aug 9 '13 at 18:03
  • We don't need you to put "edit" in your questions, every time you edit them; we certainly don't need to see it in large, bold type. All questions posted on an SE site come with a comprehensive edit history that everyone can look at. – Robert Harvey Aug 9 '13 at 20:27

You are overlooking the forest for the trees. The great majority of parsing algorithms have parse trees as their output, and virtually every treatise on parsing starts with arithmetic expressions as an example. Get any textbook, and chances are you can simply lift an algorithm from their examples, whether it's a recursive-descent parser, an LR parser or something else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.