Q. In a binary tree, how many edges are there if there are n nodes?
Show solution
Solution
In a binary tree, the number of edges is always one less than the number of nodes, hence there are n-1 edges for n nodes.
Correct Answer:
A
— n-1
Learn More →
Q. In a binary tree, what is the maximum number of leaf nodes?
A.
n
B.
n/2
C.
2^(h-1)
D.
2^h
Show solution
Solution
In a binary tree of height h, the maximum number of leaf nodes is 2^(h-1), which occurs in a complete binary tree.
Correct Answer:
C
— 2^(h-1)
Learn More →
Q. In a complete binary tree, how many nodes are there at level k?
A.
2^k
B.
2^(k+1)
C.
2^(k-1)
D.
k^2
Show solution
Solution
In a complete binary tree, the number of nodes at level k is given by 2^k, where k starts from 0 for the root level.
Correct Answer:
A
— 2^k
Learn More →
Q. What is the space complexity of a breadth-first traversal of a binary tree?
A.
O(n)
B.
O(log n)
C.
O(1)
D.
O(n log n)
Show solution
Solution
The space complexity of a breadth-first traversal is O(n) because it needs to store all nodes at the current level in the queue.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of a binary search algorithm on a sorted array?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
The time complexity of binary search on a sorted array is O(log n) because it repeatedly divides the search interval in half.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of finding the maximum element in a binary search tree?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
Finding the maximum element in a binary search tree involves traversing to the rightmost node, which takes O(log n) time in a balanced tree.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of searching for an element in a binary search tree (BST) in the average case?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
In a balanced binary search tree, the average time complexity for searching an element is O(log n) because each comparison allows the search to skip about half of the tree.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the worst-case time complexity for inserting an element into a binary search tree?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
In the worst case, a binary search tree can become unbalanced (like a linked list), leading to a time complexity of O(n) for insertion.
Correct Answer:
C
— O(n)
Learn More →
Q. Which of the following is true about the level-order traversal of a binary tree?
A.
It is depth-first
B.
It uses a stack
C.
It visits nodes level by level
D.
It is faster than in-order traversal
Show solution
Solution
Level-order traversal visits nodes level by level, typically implemented using a queue.
Correct Answer:
C
— It visits nodes level by level
Learn More →
Q. Which traversal method visits the nodes of a binary tree in the order of left child, root, right child?
A.
Pre-order
B.
In-order
C.
Post-order
D.
Level-order
Show solution
Solution
In-order traversal visits the left child first, then the root, and finally the right child, which results in the nodes being visited in ascending order for a binary search tree.
Correct Answer:
B
— In-order
Learn More →
Showing 1 to 10 of 10 (1 Pages)