Data Structures MCQs - Trees and Binary Search Trees (Set 2)

Data Structures MCQs - Trees and Binary Search Trees (Set 2) - CodingHumans

Trees are the first non-linear data structure most students meet, and they appear in almost every DSA interview. This set covers binary tree properties, the three depth-first traversals, binary search tree operations and balanced trees such as AVL.

How to practise: read each question and tap the option you think is correct. You will see right away whether you got it, along with a short explanation, and your score is tracked at the bottom of the screen. This set has 16 questions.

Q1. What is the maximum number of nodes in a binary tree of height h, if a single-node tree has height 0?

a) 2^h

b) 2^(h+1) - 1

c) 2^h - 1

d) h^2

Q2. In any binary tree, if n0 is the number of leaf nodes and n2 is the number of nodes with two children, then:

a) n0 = n2

b) n0 = n2 + 1

c) n2 = n0 + 1

d) n0 = 2 * n2

Q3. Which traversal of a binary search tree prints the keys in sorted (ascending) order?

a) Preorder

b) Inorder

c) Postorder

d) Level order

Q4. The preorder traversal of a binary tree is A B D E C F and the inorder traversal is D B E A F C. What is its postorder traversal?

a) D E B F C A

b) D B E F C A

c) E D B F C A

d) D E B C F A

Q5. Which traversal should be used to delete (free) every node of a tree safely?

a) Preorder

b) Inorder

c) Postorder

d) Any traversal works equally well

Q6. In which traversal is the root node always visited first?

a) Inorder

b) Preorder

c) Postorder

d) Reverse inorder

Q7. The keys 50, 30, 70, 20, 40, 60, 80 are inserted in that order into an empty BST. What is the height of the tree (a single node has height 0)?

a) 1

b) 2

c) 3

d) 6

Q8. Inserting the keys 10, 20, 30, 40, 50 in that order into an empty (unbalanced) BST produces a tree whose search time is:

a) O(1)

b) O(log n)

c) O(n)

d) O(n log n)

Q9. When deleting a node with two children from a BST, it is replaced by its:

a) Parent

b) Left child always

c) Inorder successor (or inorder predecessor)

d) Any leaf node

Q10. Where is the minimum key in a non-empty BST found?

a) At the root

b) At the leftmost node

c) At the rightmost node

d) At any leaf

Q11. In an AVL tree, the balance factor of every node must be:

a) Exactly 0

b) -1, 0 or +1

c) Between -2 and +2

d) Always positive

Q12. Inserting 30, 20, 10 into an empty AVL tree triggers which rotation?

a) Single left rotation

b) Single right rotation

c) Left-right double rotation

d) No rotation

Q13. What is the worst-case search time in an AVL tree with n nodes?

a) O(1)

b) O(log n)

c) O(n)

d) O(n log n)

Q14. What is the minimum possible height of a binary tree with 15 nodes, if a single-node tree has height 0?

a) 3

b) 4

c) 7

d) 14

Q15. How many structurally different binary trees can be formed with 3 nodes?

a) 3

b) 4

c) 5

d) 6

Q16. Which data structure is most commonly used to implement prefix (autocomplete) search over a dictionary of words?

a) Heap

b) Trie

c) AVL tree

d) Circular queue

Recommended MCQs

More Data Structures posts on CodingHumans

All MCQ sets

MCQ Practice hub - every subject in one place

Comments

Answered 0/0Correct 0