Suppose we represent an algebraic expression as a list whose head is an operator
ID: 3119928 • Letter: S
Question
Suppose we represent an algebraic expression as a list whose head is an operator and whose tail is a list of operands. For example, the expression a + ƒ(b, c, d) would be represented as +, a, ƒ, b, c, d. The list represents a tree whose root is the head of the list and whose subtrees are the operands, ordered from left to right. Given the list
+, 1, *, x, +, 2, *, x, +, 3, *, x, 4 .
Write out the algebraic expression represented by the list (where * is the
operation of multiplication).
Answer:
Draw the tree that the list represents.
Answer:
Explanation / Answer
A tree consisting of subtrees is given in the question. To answer it, we must solve the subtrees one by one, computing the operations that are needed, and finally get the answer. This is done as follows -
+, 1, *, x, +, 2, *, x, +, 3, *, x, 4
Since the ordering is from the left, we need to look at +, 1, *, x, ... first. However, you can see that in this, there are further subtrees to the right of "x". Thus, we need to first solve the expression where no further subtrees are being made, and then continue solving until we get the answer. This goes as follows -
+, 1, *, x, +, 2, *, x, +, 3, *, x, 4
= +, 1, *, x, +, 2, *, x, +, 3, 4x (since *, x, 4means doing the multiplication operation on x and 4)
= +, 1, *, x, +, 2, *, x, 3 + 4x
= +, 1, *, x, +, 2, x,(3 + 4x)
= +, 1, *, x, 2 +, x,(3 + 4x)
= +, 1, x( 2 +, x,(3 + 4x))
= 1 + x( 2 +, x,(3 + 4x))
= 1 + x(2 + 3x + 4x2)
= 1 + 2x + 3x2 + 4x3 Ans
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.