Discussion:
[Tutor] Binary tree expressions
Quiles, Stephanie
2015-08-18 14:36:37 UTC
Permalink
Hello!

Not sure if anyone can help me with these or not but here it goes...

I have to draw an expression tree for the following (a+b)*c-(d-e).

I believe that the last move would go first in the tree so in this case you would subtract c after computing what d-e was. So my tree would start out looking like this :

(-)
/ \
(+) (-)
/ \ / \

Sorry not sure how to better draw that...

Is that correct so far? Where do I go from there if I am? The c is really throwing me off here.

Here's the other tree:
((a+b) *c-(d-e)) ^ (f+g)

So for this one you would do everything in the double parentheses first so a+b and d-e then multiple the sum of a+b by c
Then I would subtract c from the sum of d-e.

Then I would look at the right side and add f+g

Finally I would calculate the sum of the left side ^ of the sum of f+g.
So my tree would start with the ^ its children would be * (left child) + (right child)
Is that right so far?

Thanks for your help in advance! The tutorials online are not quite as complicated so I get consider once you start adding in more operators.



Stephanie Quiles
Sent from my iPhone
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Danny Yoo
2015-08-18 23:13:19 UTC
Permalink
Apologies for not sending this to the list. Forwarding.
---------- Forwarded message ----------
From: "Danny Yoo" <***@gmail.com>
Date: Aug 18, 2015 4:12 PM
Subject: Re: [Tutor] Binary tree expressions
To: "Stephanie Quiles" <***@albright.edu>
Cc:


On Aug 18, 2015 3:48 PM, "Quiles, Stephanie" <
***@albright.edu> wrote:
>
> Hello!
>
> Not sure if anyone can help me with these or not but here it goes...
>

You might find the following helpful:

http://www.bootstrapworld.org/materials/fall2015/courses/bs1/units/unit1/index.html#lesson_OrderofOperations5272

After reading that, try doing some of these exercises:

http://www.bootstrapworld.org/materials/fall2015/lessons/Order-of-Operations/exercises/match-arith-coe1.html

http://www.bootstrapworld.org/materials/fall2015/lessons/Order-of-Operations/exercises/arith-to-coe1.html

If you have any questions, please feel free to ask.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Quiles, Stephanie
2015-08-19 15:09:44 UTC
Permalink
Yes I got the exact same thing. I figured it out once I sent the email. It is easier to start the tree from the bottom and work your way up than the way I was doing it which was from the top down. Thanks for your reply Alex, it was still helpful to get someone else's interpretation



Stephanie Quiles
Sent from my iPhone

> On Aug 19, 2015, at 2:41 AM, Alex Kleider <***@sonic.net> wrote:
>
>> On 2015-08-18 07:36, Quiles, Stephanie wrote:
>> Hello!
>> Not sure if anyone can help me with these or not but here it goes...
>> I have to draw an expression tree for the following (a+b)*c-(d-e).
>> I believe that the last move would go first in the tree so in this
>> case you would subtract c after computing what d-e was. So my tree
>> would start out looking like this :
>> (-)
>> / \
>> (+) (-)
>> / \ / \
>> Sorry not sure how to better draw that...
>> Is that correct so far? Where do I go from there if I am? The c is
>> really throwing me off here.
>> Here's the other tree:
>> ((a+b) *c-(d-e)) ^ (f+g)
>> So for this one you would do everything in the double parentheses
>> first so a+b and d-e then multiple the sum of a+b by c
>> Then I would subtract c from the sum of d-e.
>> Then I would look at the right side and add f+g
>> Finally I would calculate the sum of the left side ^ of the sum of f+g.
>> So my tree would start with the ^ its children would be * (left child)
>> + (right child)
>> Is that right so far?
>
> Here's how I interpret the issue:
>
> (a+b)*c-(d-e)
>
>
> -
> / \
> * -
> / \ / \
> + c d e
> / \
> a b
>
> ((a+b) *c-(d-e)) ^ (f+g)
>
> ^
> / \
> - +
> / \ / \
> * - f g
> / \ / \
> + c d e
> / \
> a b
>
> If I understand the problem correctly, it seems to be a test of your ability to understand precedence as in 'order of operation.'
>
> Parentheses trump any of the following.
> ^ is highest of the ones involved here.
> * is next (as is division but that's not involved here)
> + and - are lowest.
>
> Hope this helps.
>
>
> <bin_tree>
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Loading...