tree_theroy_question
tree_theroy_question
1. Which traversal technique visits nodes in the order: left, root, right?
A) Preorder
B) Inorder
C) Postorder
D) Level order
Answer: B) Inorder
Explanation: Inorder traversal in a binary tree involves visiting the left subtree, then the root, and
finally the right subtree.
2. Which of the following data structures is used in implementing a binary tree level-order
traversal?
A) Stack
B) Queue
C) Array
D) Linked list
Answer: B) Queue
Explanation: Level-order traversal uses a queue to visit nodes level by level.
4. What is the height of an AVL tree with n nodes in the worst case?
A) O(log n)
B) O(n)
C) O(nlog n)
D) O(n2)
Answer: A) O(log n)
Explanation: AVL trees are balanced, so the height is logarithmic, ensuring efficient operations.
5. Which rotation is performed when an AVL tree has an imbalance with a left-left case?
A) Left rotation
B) Right rotation
C) Left-right rotation
D) Right-left rotation
Answer: B) Right rotation
Explanation: A left-left imbalance is corrected by a single right rotation.
6. In a binary tree, which traversal visits nodes in root, left, right order?
A) Inorder
B) Preorder
C) Postorder
D) Level order
Answer: B) Preorder
Explanation: Preorder traversal visits the root first, followed by the left and right subtrees.
7. In an AVL tree, what is the maximum difference allowed between the heights of left and right
subtrees?
A) 0
B) 1
C) 2
D) No limit
Answer: B) 1
Explanation: The balance factor of any node in an AVL tree should not exceed 1 to maintain balance.
8. In a binary tree, which traversal technique can be implemented without recursion or stack?
A) Preorder
B) Inorder
C) Postorder
D) Level order
A) 2h−1
B) 2h+1−1
C) 2h−1
D) 2h−1−1
Answer: B) 2h+1−1
Explanation: A full binary tree of height h has 2h+1−1 nodes.
11. In an AVL tree, if inserting a node causes a left-left imbalance, which rotation will correct this?
A) Left rotation
B) Right rotation
C) Left-right rotation
D) Right-left rotation
12. In a binary tree, how many edges are there if the tree has n nodes?
A) n−1
B) n
C) n+1
D) 2n
Answer: A) n−1
Explanation: A binary tree with n nodes has n-1 edges.
13. If a node with one child is deleted from a BST, what happens to the child node?
A) It is deleted as well
B) It replaces the deleted node
C) It becomes a new root node
D) No change occurs
14. If a BST is built by inserting the elements 30, 10, 20, 40, 50, what would be the in-order
traversal of the BST?
A) 30 10 20 40 50
B) 10 20 30 40 50
C) 50 40 30 20 10
D) 10 30 20 40 50
Answer: B) 10 20 30 40 50
Explanation: In-order traversal of a BST lists elements in sorted ascending order.
15. Which of the following statements is true about AVL trees compared to BSTs?
Answer: B) The number of edges on the longest path from the root to a leaf
Explanation: Option B is correct. The height of a binary tree is the number of edges on the longest
path from the root to a leaf.
A) An operator
B) An operand
C) A function
D) A variable
Answer: B) An operand
Explanation: Option B is correct. In an expression tree, a leaf node represents an operand, which can
be a constant or a variable.