Expression Tree Multiple Choice Questions and Answers (MCQs)

Uncategorized

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

1. 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)

Explanation: The average depth of a binary expression tree is calculated to be O(N) mathematically.

2. Only infix expression can be made into an expression tree.
A) true
B) false
Explanation: Using the right algorithms, any infix, prefix, or postfix expression can be turned into an expression tree.

3. An expression tree is created using?
A) postfix expression
B) prefix expression
C) infix expression
D) paranthesized expression

Explanation: By reading one symbol at a time and creating a tree, a postfix expression is transformed into an expression tree.

4. ++a*bc*+defg is an?
A) postfix expression
B) infix expression
C) prefix expression
D) invalid expression

Explanation: Since it is of the form operator-operand-operand, it is a prefix expression obtained from a preorder traversal.

5. An expression tree’s nodes can be deleted by calling?
A) malloc
B) calloc
C) delete
D) free

Explanation: In binary trees, nodes are created by calling malloc and removed by calling free.

6. What is the postfix expression for the following expression tree?

A) abcde++**
B) ab+cde+**
C) abc+de+**
D) abcd+*e+*

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

7. 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

Explanation: Create one node trees and transfer them onto the stack when an operand is encountered. Pop the pointers from the last two trees from the stack when an operator is encountered.

8. The leaves of an expression tree always contain?
A) operators
B) operands
C) null
D) expression

Explanation: The product of a given expression (i.e. operands) is often contained in the leaves of an expression tree.

9. A node can have a minimum of one child.
A) true
B) false

Explanation: A node can have at least one child, as shown by the unary minus operator.

10. 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

Explanation: Operators are often present in nodes other than leaves. In those nodes, there can’t be any operand.

11. An expression tree is a kind of?
A) Binary search tree
B) Fibonacci tree
C) Binary tree
D) Treap

Explanation: A binary tree is used to represent the expression tree. It has operands at the leaf nodes and operators at the remaining nodes. Any combination of operands and operators can be used (ascending, descending).

13. 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

Explanation: Since the format of an infix expression is operand-operator-operand, it is an infix expression.

An expression tree is a representation of expressions in a data structure that resembles a tree. In other words, it’s a tree where the operands are the leaves and the operators are the nodes. Expression trees are primarily used to analyse, evaluate, and modify expressions, especially complex ones. Operands, such as constants or variable names, are found at the leaves of a binary expression tree, while operators are found at the other nodes. These trees are binary since all of the operations are binary, and despite the fact that this is the simplest case, nodes can have more than two children.

Leave a Reply

Your email address will not be published. Required fields are marked *