00:01
In part a, we're given an expression, and we're asked to represent this expression using a binary tree.
00:11
So we're given the expression x plus 2 the third power times y minus 3 plus x minus 5.
00:22
So to construct the binary tree to represent this expression, first we construct some subtrees.
00:33
So we'll have the sub -tree representing x plus 2.
00:40
We'll also have the sub -tree representing 3 plus x.
00:54
Next, we'll create the sub -tree representing x plus 2 to the third power, and we'll also construct the sub -tree representing y -minus 3 -plus -x.
01:43
Using these two sub -trees, first we'll construct the sub -tree x plus 2 to the third -power.
01:51
Times y minus 3 plus x and finally using this subtree will construct the binary trade for the full expression we have a rooted binary tree with root minus and on the left we're going to have our sub tree with root star and star has children power and minus exponentiation and subtraction extenation has children plus and three, plus has children x and two, minus has children y and plus, addition, i should say.
04:02
Addition has children three and x.
04:09
And then we see that minus also has a child five.
04:13
So this is the binary tree representing this expression.
04:27
Now in part b, we're asked to write the expression using prefix notation.
04:31
So let's make a prefix proversal of this tree that we've constructed so i'm going to start off with our root minus followed by the subtree with root star star as we determined as children exponentiation say multiplication as children exponentiation and subtraction expansiation is children addition addition and three.
05:34
In addition, it's children, x and two.
05:37
There are a fast ways to do this if you'd like them just being explicit here.
05:42
And subtraction has children y and addition.
05:47
Addition has children three and x.
05:55
This is followed by the subtree or the prefix, the prefix traversal of the subtree with root 5, which is simply 5.
06:10
So in the next step, we have minus, followed by the subtree, or the prefix traversal of the subtree with root exponentiation.
06:31
So we have exponentiation.
06:36
I guess we should really have the root multiplication first, then exponentiation.
06:44
Exponitiation has children addition and three, addition has children x and two, followed by the prefix traversal of the subtree with root subtraction.
07:09
You see that subtraction has children y and addition...