Expression Tree Multiple Choice Questions and Answers (MCQs)

«
»

This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Expression Tree”.

1. The leaves of an expression tree always contain?
a) operators
b) operands
c) null
d) expression
View Answer

Answer: b
Explanation: The leaves of an expression tree always contain the result of a given expression (i.e.) operands.
advertisement

2. A node can have a minimum of one child.
a) true
b) false
View Answer

Answer: a
Explanation: It is possible for a node to have at least one child, as is the case with the unary minus operator.

3. What does the other nodes of an expression tree(except leaves) contain?
a) only operands
b) only operators
c) both operands and operators
d) expression
View Answer

Answer: b
Explanation: The nodes other than leaves always contain only operators. There cannot be any operand in those nodes.
advertisement
advertisement

4. An expression tree is a kind of?
a) Binary search tree
b) Fibonacci tree
c) Binary tree
d) Treap
View Answer

Answer: c
Explanation: The expression tree is a binary tree. It contains operands at leaf nodes and remaining nodes are filled with operators. The operands and the operators can be arranged in any order (ascending, descending).

5. The expression obtained by recursively producing a left expression, followed by an operator, followed by recursively producing a right expression is called?
a) prefix expression
b) infix expression
c) postfix expression
d) paranthesized expression
View Answer

Answer: b
Explanation: It is an infix expression because the format of an infix expression is given by operand-operator-operand.
advertisement

6. The average depth of a binary tree is given as?
a) O(N)
b) O(log N)
c) O(M log N)
d) O(√N)
View Answer

Answer: d
Explanation: The average depth of a binary expression tree is mathematically found to be O(√N).

7. Only infix expression can be made into an expression tree.
a) true
b) false
View Answer

Answer: b
Explanation: All infix, prefix and postfix expressions can be made into an expression tree using appropriate algorithms.
advertisement

8. An expression tree is created using?
a) postfix expression
b) prefix expression
c) infix expression
d) paranthesized expression
View Answer

Answer: a
Explanation: A postfix expression is converted into an expression tree by reading one symbol at a time and constructing a tree respectively.

9. ++a*bc*+defg is an?
a) postfix expression
b) infix expression
c) prefix expression
d) invalid expression
View Answer

Answer: c
Explanation: It is a prefix expression obtained from a preorder traversal since it is of the form operator-operand-operand.
advertisement

10. An expression tree’s nodes can be deleted by calling?
a) malloc
b) calloc
c) delete
d) free
View Answer

Answer: d
Explanation: In Binary trees, nodes are created by calling malloc and they are deleted by calling free.

11. What is the postfix expression for the following expression tree?
expression-tree-questions-answers-q11
a) abcde++**
b) ab+cde+**
c) abc+de+**
d) abcd+*e+*
View Answer

Answer: b
Explanation: If the given expression tree is evaluated, the postfix expression ab+cde+** is obtained.

12. In an expression tree algorithm, what happens when an operand is encountered?
a) create one node pointing to a stack
b) pop the nodes from the stack
c) clear stack
d) merge all the nodes
View Answer

Answer: a
Explanation: When an operand is encountered, create one node trees and push it on to the stack. When an operator is encountered, pop the pointers from last two trees from the stack.

Sanfoundry Global Education & Learning Series – Data Structure.

To practice all areas of Data Structure, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter