Back to Practice Data Structures

Trees - Practice MCQs for CCAT

50 Questions Section B: Programming Data Structures

Trees Question Bank for C-CAT

Topic-wise Trees MCQs for CDAC C-CAT preparation with answers and explanations.

Q1.
Maximum nodes at level k in binary tree:
Ak
B2k
C2k
D2(k+1)
Show Answer & Explanation

Correct Answer: B - 2k

At level k (0-indexed), max nodes = 2k. Level 0 has 1, level 1 has 2, etc.

Q2.
A binary tree with n nodes has __ NULL pointers:
An+1
Bn
Cn-1
D2n
Show Answer & Explanation

Correct Answer: A - n+1

A binary tree with n nodes has n+1 NULL pointers.

Q3.
Height of complete binary tree with n nodes:
An
Bn/2
C
Dlog n
Show Answer & Explanation

Correct Answer: D - log n

Height of complete binary tree is O(log n).

Q4.
Inorder traversal of BST gives:
ASorted order
BRandom order
CReverse sorted
DLevel order
Show Answer & Explanation

Correct Answer: A - Sorted order

Inorder traversal of BST gives elements in sorted (ascending) order.

Q5.
In BST, search operation takes:
AO(1)
BO(n)
CO(log n) average
DO(n²)
Show Answer & Explanation

Correct Answer: C - O(log n) average

BST search is O(log n) on average, O(n) worst case (skewed tree).

Q6.
AVL tree is:
AUnbalanced BST
BSelf-balancing BST
CNot a binary tree
DGeneral tree
Show Answer & Explanation

Correct Answer: B - Self-balancing BST

AVL tree is a self-balancing BST where height difference of subtrees ≤ 1.

Q7.
Level order traversal uses:
AStack
BArray
CQueue
DLinked List
Show Answer & Explanation

Correct Answer: C - Queue

Level order (BFS) traversal uses queue.

Q8.
The root of a tree has:
ATwo parents
BOne parent
CNo parent
DMultiple parents
Show Answer & Explanation

Correct Answer: C - No parent

Root is the topmost node with no parent.

Q9.
A tree with n nodes has __ edges:
An
B2n
Cn+1
Dn-1
Show Answer & Explanation

Correct Answer: D - n-1

A tree with n nodes always has exactly n-1 edges.

Q10.
Full binary tree means:
AAll levels filled
BMaximum nodes
CEvery node has 0 or 2 children
DNo leaves
Show Answer & Explanation

Correct Answer: C - Every node has 0 or 2 children

In full binary tree, every node has either 0 or 2 children.

Q11.
Complete binary tree has:
AAll levels completely filled
BOnly left children
CAll levels filled except possibly last, filled left to right
DOnly right children
Show Answer & Explanation

Correct Answer: C - All levels filled except possibly last, filled left to right

Complete binary tree has all levels filled except possibly the last, which is filled from left to right.

Q12.
Perfect binary tree has:
AOnly one child per node
BAll internal nodes have 2 children and all leaves at same level
CRandom structure
DNo leaves
Show Answer & Explanation

Correct Answer: B - All internal nodes have 2 children and all leaves at same level

Perfect binary tree has all internal nodes with 2 children and all leaves at the same level.

Q13.
Preorder traversal visits nodes in order:
ALeft, Root, Right
BRight, Left, Root
CLeft, Right, Root
DRoot, Left, Right
Show Answer & Explanation

Correct Answer: D - Root, Left, Right

Preorder: Root first, then Left subtree, then Right subtree (Root-Left-Right).

Q14.
Postorder traversal visits nodes in order:
ALeft, Root, Right
BLeft, Right, Root
CRoot, Left, Right
DRight, Root, Left
Show Answer & Explanation

Correct Answer: B - Left, Right, Root

Postorder: Left subtree first, then Right subtree, then Root (Left-Right-Root).

Q15.
Minimum height of binary tree with n nodes:
An
Bfloor(log2(n))
Cn-1
Dn/2
Show Answer & Explanation

Correct Answer: B - floor(log2(n))

Minimum height is achieved in complete binary tree: floor(log2(n)).

Q16.
Red-Black tree guarantees:
AO(1) operations
BO(n) search
CO(log n) worst case operations
DUnbalanced structure
Show Answer & Explanation

Correct Answer: C - O(log n) worst case operations

Red-Black tree is self-balancing, guaranteeing O(log n) for search, insert, delete.

Q17.
B-tree is commonly used in:
ARAM storage
BString matching
CNetwork routing
DDatabase indexing and file systems
Show Answer & Explanation

Correct Answer: D - Database indexing and file systems

B-trees are optimized for disk access and widely used in databases and file systems.

Q18.
Lowest Common Ancestor (LCA) of two nodes is:
ARoot always
BLeftmost common node
CDeepest node that is ancestor of both
DRightmost common node
Show Answer & Explanation

Correct Answer: C - Deepest node that is ancestor of both

LCA is the deepest (lowest) node that has both given nodes as descendants.

Q19.
Binary heap is used to implement:
AStack
BQueue
CPriority Queue
DHash table
Show Answer & Explanation

Correct Answer: C - Priority Queue

Binary heap efficiently implements priority queue with O(log n) insert and extract.

Q20.
Threaded binary tree uses NULL pointers to store:
AInorder predecessor/successor
BRandom values
CLevel order info
DDepth info
Show Answer & Explanation

Correct Answer: A - Inorder predecessor/successor

Threaded binary tree uses NULL pointers to store inorder predecessor or successor for efficient traversal.

Q21.
What is the maximum number of nodes in a binary tree of height h?
A2h
B2(h+1) - 1
C2h - 1
D2(h+1)
Show Answer & Explanation

Correct Answer: B - 2(h+1) - 1

A binary tree of height h can have at most 2(h+1) - 1 nodes, achieved when every level is completely filled (perfect binary tree).

Q22.
In a Binary Search Tree (BST), which traversal produces elements in sorted (ascending) order?
APreorder
BInorder
CPostorder
DLevel order
Show Answer & Explanation

Correct Answer: B - Inorder

Inorder traversal of a BST visits left subtree, root, then right subtree, which produces elements in ascending sorted order.

Q23.
What is the time complexity of searching for an element in a balanced BST with n nodes?
AO(n)
BO(log n)
CO(n log n)
DO(1)
Show Answer & Explanation

Correct Answer: B - O(log n)

In a balanced BST, the height is O(log n), so searching takes O(log n) time as we traverse from root to leaf at most.

Q24.
Which of the following is NOT a valid binary tree traversal method?
ARandomorder
BPreorder
CInorder
DPostorder
Show Answer & Explanation

Correct Answer: A - Randomorder

Randomorder is not a standard tree traversal method. The three standard depth-first traversals are Inorder, Preorder, and Postorder.

Q25.
In a max-heap, the value of each node is:
AGreater than or equal to its children
BLess than its children
CEqual to its children
DLess than or equal to its parent and children
Show Answer & Explanation

Correct Answer: A - Greater than or equal to its children

In a max-heap, the value of each node is greater than or equal to the values of its children, ensuring the maximum element is at the root.

Q26.
What is the minimum number of nodes in an AVL tree of height 3?
A7
B5
C4
D8
Show Answer & Explanation

Correct Answer: A - 7

The minimum number of nodes in an AVL tree of height h follows N(h) = N(h-1) + N(h-2) + 1. N(0)=1, N(1)=2, N(2)=4, N(3)=7.

Q27.
Which rotation is applied in an AVL tree when a node is inserted into the right subtree of the left child (LR case)?
ASingle left rotation
BSingle right rotation
CRight-Left double rotation
DLeft-Right double rotation
Show Answer & Explanation

Correct Answer: D - Left-Right double rotation

The LR case requires a Left-Right double rotation: first a left rotation on the left child, then a right rotation on the unbalanced node.

Q28.
The preorder traversal of a binary tree visits nodes in which order?
ALeft, Root, Right
BRoot, Left, Right
CLeft, Right, Root
DRight, Root, Left
Show Answer & Explanation

Correct Answer: B - Root, Left, Right

Preorder traversal visits the Root first, then recursively visits the Left subtree, followed by the Right subtree.

Q29.
A complete binary tree with n nodes has how many leaf nodes?
A⌈n/2⌉
Bn/2
C⌊n/2⌋
Dn/2 + 1
Show Answer & Explanation

Correct Answer: A - ⌈n/2⌉

A complete binary tree with n nodes has ⌈n/2⌉ leaf nodes. This is because internal nodes occupy positions 1 to ⌊n/2⌋.

Q30.
What is the worst-case time complexity of insertion in an unbalanced BST?
AO(1)
BO(log n)
CO(n)
DO(n log n)
Show Answer & Explanation

Correct Answer: C - O(n)

In the worst case, a BST can degenerate into a linked list (skewed tree), making the insertion time complexity O(n).

Q31.
Which data structure is used to implement a priority queue efficiently?
AStack
BQueue
CLinked List
DHeap
Show Answer & Explanation

Correct Answer: D - Heap

A heap (min-heap or max-heap) is the most efficient data structure for implementing a priority queue, providing O(log n) insertion and extraction.

Q32.
In a BST, to delete a node with two children, it is replaced with:
AIts left child
BIts inorder successor or predecessor
CIts right child
DThe root node
Show Answer & Explanation

Correct Answer: B - Its inorder successor or predecessor

When deleting a node with two children in a BST, it is replaced by its inorder successor (smallest in right subtree) or inorder predecessor (largest in left subtree).

Q33.
The height of a complete binary tree with n nodes is:
A⌈log₂(n)⌉
B⌊log₂(n)⌋
Clog₂(n) + 1
Dn - 1
Show Answer & Explanation

Correct Answer: B - ⌊log₂(n)⌋

The height of a complete binary tree with n nodes is ⌊log₂(n)⌋, as the tree is filled level by level.

Q34.
Which of the following is true about a full binary tree?
AAll leaves are at different levels
BEvery level is completely filled
CIt has exactly 2h nodes
DEvery node has 0 or 2 children
Show Answer & Explanation

Correct Answer: D - Every node has 0 or 2 children

A full (or strictly) binary tree is one where every node has either 0 or 2 children. No node has exactly one child.

Q35.
What is the balance factor of a node in an AVL tree?
AHeight of left subtree + height of right subtree
BDepth of left subtree × depth of right subtree
CNumber of left nodes - number of right nodes
DHeight of left subtree - height of right subtree
Show Answer & Explanation

Correct Answer: D - Height of left subtree - height of right subtree

The balance factor of a node in an AVL tree is defined as the height of its left subtree minus the height of its right subtree. It must be -1, 0, or 1.

Q36.
Level order traversal of a binary tree uses which data structure?
AStack
BDeque
CPriority Queue
DQueue
Show Answer & Explanation

Correct Answer: D - Queue

Level order (BFS) traversal uses a queue. Nodes are enqueued level by level and dequeued in FIFO order for processing.

Q37.
How many distinct binary trees can be formed with 3 distinct nodes?
A3
B5
C12
D30
Show Answer & Explanation

Correct Answer: D - 30

With 3 distinct nodes, the number of distinct binary trees = Catalan(3) × 3! = 5 × 6 = 30. Catalan number gives structurally unique trees, multiplied by permutations of labels.

Q38.
In a min-heap with n elements, where is the maximum element located?
AAt one of the leaf nodes
BAt the root
CAt the second level
DAt the last internal node
Show Answer & Explanation

Correct Answer: A - At one of the leaf nodes

In a min-heap, the maximum element is always at one of the leaf nodes since every parent is smaller than its children.

Q39.
The postorder traversal of a binary tree visits nodes in which order?
ARoot, Left, Right
BLeft, Root, Right
CLeft, Right, Root
DRight, Left, Root
Show Answer & Explanation

Correct Answer: C - Left, Right, Root

Postorder traversal visits the Left subtree first, then the Right subtree, and finally the Root node.

Q40.
What is the time complexity of building a heap from an unsorted array of n elements?
AO(n)
BO(n log n)
CO(n²)
DO(log n)
Show Answer & Explanation

Correct Answer: A - O(n)

Building a heap using the bottom-up (heapify) approach takes O(n) time, which is more efficient than inserting elements one by one (O(n log n)).

Q41.
Which of the following trees is a self-balancing binary search tree?
ABinary tree
BComplete binary tree
CFull binary tree
DAVL tree
Show Answer & Explanation

Correct Answer: D - AVL tree

An AVL tree is a self-balancing BST where the balance factor of every node is maintained between -1 and 1 through rotations.

Q42.
If a binary tree has 10 leaf nodes, how many nodes with exactly 2 children does it have?
A10
B9
C11
DCannot be determined
Show Answer & Explanation

Correct Answer: B - 9

For any binary tree, the number of nodes with 2 children = number of leaf nodes - 1. So it has 10 - 1 = 9 such nodes.

Q43.
In a BST, the inorder predecessor of a node is:
AThe rightmost node in its left subtree
BThe leftmost node in its right subtree
CIts parent node
DThe root of the tree
Show Answer & Explanation

Correct Answer: A - The rightmost node in its left subtree

The inorder predecessor of a node in a BST is the rightmost (maximum) node in its left subtree.

Q44.
What is the space complexity of a recursive inorder traversal of a binary tree with n nodes?
AO(n)
BO(log n)
CO(1)
DO(n log n)
Show Answer & Explanation

Correct Answer: A - O(n)

The space complexity is O(n) in the worst case (skewed tree) due to the recursion stack. For a balanced tree, it is O(log n).

Q45.
A binary heap is typically implemented using which data structure?
AArray
BLinked list
CBinary search tree
DHash table
Show Answer & Explanation

Correct Answer: A - Array

A binary heap is typically implemented using an array where for a node at index i, its children are at 2i+1 and 2i+2, making it space-efficient.

Q46.
Which operation on a max-heap has O(log n) time complexity?
AFinding the maximum element
BFinding the minimum element
CInserting an element
DAccessing a random element
Show Answer & Explanation

Correct Answer: C - Inserting an element

Inserting an element into a max-heap takes O(log n) time as the element may need to be bubbled up from leaf to root. Finding max is O(1) since it's at the root.

Q47.
The number of edges in a tree with n nodes is:
An
Bn - 1
Cn + 1
D2n - 1
Show Answer & Explanation

Correct Answer: B - n - 1

A tree with n nodes always has exactly n - 1 edges. This is a fundamental property of trees.

Q48.
Given a BST with keys {1, 2, 3, 4, 5} inserted in order, the resulting tree will be:
AA right-skewed tree
BA balanced BST
CA left-skewed tree
DA complete binary tree
Show Answer & Explanation

Correct Answer: A - A right-skewed tree

Inserting sorted keys {1, 2, 3, 4, 5} into a BST produces a right-skewed tree where each node has only a right child.

Q49.
Which traversal is used to create a copy of a binary tree?
AInorder
BLevel order
CPostorder
DPreorder
Show Answer & Explanation

Correct Answer: D - Preorder

Preorder traversal is used to create a copy of a binary tree because it processes the root before its subtrees, allowing proper tree construction.

Q50.
In an AVL tree, after an insertion causes imbalance, at most how many rotations are needed to restore balance?
A1
B3
C2
Dlog n
Show Answer & Explanation

Correct Answer: C - 2

After an insertion in an AVL tree, at most 2 rotations (a double rotation) are needed to restore balance at the first unbalanced ancestor.

Showing 1-10 of 50 questions