0

In my exam I got this expression and failed to construct binary tree. what would be the solution?

(5a-3b)^2*(3a+5b)^3

I drew the tree from above expression like

            *
           / \
          /   \
         ^     \
        / \     \
       /   \     \
      -     2     ^
    /  \         / \
   /    \       +   3
  *      *     / \
 / \    / \   /   \
5   a  3  b  *     *
            / \   / \
           3   a  5  b

I got 0 from this answer! I could not understand the reason!

Can anybody help me?

Iqbal
  • 235
  • 8
  • 19
  • Edit your post and show us what you think the binary tree should be. – rob mayoff Oct 20 '12 at 05:02
  • I drew sir.. Can you figure out my problem please? – Iqbal Oct 20 '12 at 05:29
  • I don't see any errors in your tree. Ask your teacher. – rob mayoff Oct 20 '12 at 05:36
  • Thanks for your valuable comments – Iqbal Oct 20 '12 at 05:38
  • Honestly speaking I also can't see the reason for getting zero. Could you please share if your teacher would explain? – Serge Oct 20 '12 at 06:40
  • You consistently aren't showing neither your code/algorithm nor any effort in solving this type of problems. Your questions are bad, they aren't specific. We can't even have any idea of what you have done, how and which values of `a` and `b` you have used. For `a`=`b`=0 you can get 0 and it will be the correct result. But you aren't telling us anything. You really have to work on improving the quality of your questions. Nobody around here can read your mind and nobody is going to give your full working solutions. Help us to help you. – Alexey Frunze Oct 20 '12 at 10:22

2 Answers2

0

Constructing a binary tree doesn't mean that you just draw the graphical representation which you have shown here. I think It actually means to implement in code or may in pseudo code. So think again using stack with the same expression Convert the infix notation to postfix and you can solve it easily by using stack property.

Omkant
  • 8,362
  • 7
  • 36
  • 57
0

I am currently taking a discrete mathematics course and we are on the subject of trees. You have to remember to put each level in its own (). So I believe the tree you created would look like this as an expression: ((5*a)-(3*b))^2*((3*a)+(5*b))^3. This is an Inorder traversal of the tree. For your answer you needed to have something more like this:

                  *
                /   \
               /     \
              /       \
             ^         \
           /   \        \
          /     \        \
         -       2        ^
       /   \             /  \
      /     \           /    3
    5a       3b        +
                     /   \
                    /     \
                  3a       5b