Question: What info do u need. Thanks Recall that we can use a proper binary tree to represent a simple arithmetic expression involving the binary operators

What info do u need. Thanks

Recall that we can use a proper binary tree to represent a simple arithmetic expression involving the binary operators +, -, , and =, and where the operands can be other simple arithmetic expressions, variables, or constants. In the proper binary tree representation, the elements in the leaf nodes of the tree must be variables or constants, while the elements in an internal node (i.e., a node that is not a leaf) must be a binary operator. In prefix notation, the operator of an arithmetic expression appears first followed by the operands. For example, the prefix notation of the arithmetic expression (((3 + 1) 5) = ((9 - a) + 3)) is (= ( (+ 3 1) 5 (+ (- 9 a) 3)) : Your task is to do the following. (a) Write, using pseudocode, an algorithm printPrefix that prints out the prefix notation of an arithmetic expression represented using a proper binary tree as input. Your algorithm should be as efficient as possible. Assume that, given a node w in the tree, you can access its elem data member for the node ADT directly (i.e., in this case, w:elem is either an operator, a variable, or a constant, depending on the type of node), and that you have available the predicate function isLeaf? for the binary-tree node ADT, which outputs true if and only if the node is a leaf (i.e., w:isLeaf? = true if an only if node w is a leaf). Assume also that you can use standard print-out operations as usual: e.g., print(w:elem) prints out the element stored in node w, print(\(") prints out the left parenthesis symbol \)" and print(\ ") prints out a \white space." (b) Provide tight big-Oh expressions for the worst-case running time and space complexity of your algorithm as a function of the number of nodes n in the proper binary tree representation of the arithmetic expression (i.e., the total number of operators and operands).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!