0

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

A+(B-C)*D+E*F

should be translated into

 |-(+)-|
 | |
 |---(*)---| |---(*)---|
 | | | |
|---(+)---| D E F
| |
| |
A |--( - )--|
 | |
 B C
Robert Harvey
201k55 gold badges470 silver badges682 bronze badges
asked Aug 9, 2013 at 17:55
2
  • 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. Commented Aug 9, 2013 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. Commented Aug 9, 2013 at 20:27

1 Answer 1

1

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.

answered Aug 9, 2013 at 18:37
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.