Question: PYTHON ONLY For this assignment you are to take the parse tree as input and create and print a derivative tree. The derivative tree should
PYTHON ONLY
For this assignment you are to take the parse tree as input and create and print a derivative tree. The derivative tree should be a binary tree with the nodes that contain the normal data, left, right, and parent fields.
The derivative of an expression that involves the variable x or X can be defined by a few recursive rules:
If A is an expression, let D(A) be the derivative of A.
The derivative of a constant is 0. D(C) = 0.
The derivative of x or X is 1. D(x) = D(X) = 1.
If A and B are expressions, let D(A) be the derivative of A and D(B) be the derivative of B. Then
The D(A + B) is D(A) + D(B).
The D(A - B) is D(A) - D(B).
The D(A * B) is (A * D(B)) + (B * D(A)).


class Earselree: def init (self, value) self.value -value self.leftNone self.right None def isOperator (c) if (c == '+' or c == '-' or c == '*' or c- return True else: return False def inorder (t): iftis not None: inorder (t.left)l print (t.value) inorder (t.right) def constructTree (postfix) stack - [] for char in postfix: if not isOperator (char) t = a r s eTree (char) stack.append (t) else: t arselree (char) tl stack.pop () t2 stack.pop ( t.righttl t. left = t2 stack.append(t) t stack.pop () return t
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
