25 Lecture
CS301
Midterm & Final Term Short Notes
Expression tree
An expression tree is a binary tree in which each internal node represents an arithmetic operator and each leaf node represents an operand. The tree is constructed by recursively applying the binary operator to the operands. Expression trees can
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- What is an expression tree? a) A binary tree with nodes representing operands b) A binary tree with nodes representing operators c) A binary tree with nodes representing both operands and operators d) A binary tree with nodes representing numbers
Answer: c
- What is the purpose of an expression tree? a) To represent a mathematical expression b) To store data in a tree structure c) To sort data in a binary tree d) To perform search operations on data in a binary tree
Answer: a
- Which traversal of an expression tree is used to evaluate the expression? a) Preorder b) Inorder c) Postorder d) Level order
Answer: c
- What is the time complexity of evaluating an expression tree? a) O(n) b) O(log n) c) O(n^2) d) O(2^n)
Answer: a
- How is an expression tree created from an infix expression? a) Using the preorder traversal b) Using the inorder traversal c) Using the postorder traversal d) Using a stack
Answer: d
- What is the maximum number of children a node in an expression tree can have? a) 0 b) 1 c) 2 d) 3
Answer: c
- Which of the following operations can be performed on an expression tree? a) Insertion of a node b) Deletion of a node c) Rotation of a node d) All of the above
Answer: d
- What is the purpose of a leaf node in an expression tree? a) To represent an operator b) To represent an operand c) To represent a binary operation d) To represent a unary operation
Answer: b
- Can an expression tree have duplicate nodes? a) Yes b) No
Answer: b
- What is the advantage of using an expression tree over a postfix expression? a) Faster evaluation b) Easier to read c) Takes less space d) All of the above
Answer: d
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is an expression tree? An expression tree is a binary tree representation of expressions, where the leaves are operands, and internal nodes are operators.
How can we evaluate an expression tree? We can evaluate an expression tree recursively by evaluating the left and right subtrees and then applying the operator in the root.
What is a prefix expression? A prefix expression is an expression where the operator comes before the operands, for example, + 2 3.
How do we convert a prefix expression to an expression tree? We start from the leftmost operand and create a new node for each operator encountered, with the left child being the next operand and the right child being the next operator or operand.
What is a postfix expression? A postfix expression is an expression where the operator comes after the operands, for example, 2 3 +.
How do we convert a postfix expression to an expression tree? We start from the leftmost operand and create a new node for each operator encountered, with the right child being the next operand and the left child being the next operator or operand.
What is an infix expression? An infix expression is an expression where the operator comes between the operands, for example, 2 + 3.
How do we convert an infix expression to an expression tree? We use the shunting-yard algorithm to convert an infix expression to postfix notation and then create an expression tree from the postfix expression.
What is the height of an expression tree? The height of an expression tree is the maximum depth of any leaf node in the tree.
What is the time complexity of evaluating an expression tree? The time complexity of evaluating an expression tree is O(n), where n is the number of nodes in the tree.