Q. If a binary tree has a height of 'h', what is the minimum number of nodes it can have?
A.
h
B.
h + 1
C.
2^h - 1
D.
2^h
Show solution
Solution
The minimum number of nodes in a binary tree of height h is h + 1, which occurs in a skewed tree.
Correct Answer:
B
— h + 1
Learn More →
Q. In a binary tree, what is the maximum number of leaf nodes possible?
A.
n
B.
n/2
C.
2^h
D.
2^(h+1) - 1
Show solution
Solution
The maximum number of leaf nodes in a binary tree of height h is 2^h, as each level can have twice the number of nodes as the previous level.
Correct Answer:
C
— 2^h
Learn More →
Q. What is the average time complexity for inserting an element in a balanced binary search tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
In a balanced binary search tree, the average time complexity for insertion is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the space complexity of a recursive inorder 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 is O(h), where h is the height of the tree. In the worst case of a skewed tree, this can be O(n), but for a balanced tree, it is O(log n).
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 worst case?
A.
O(log n)
B.
O(n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
In the worst case, a binary search tree can become unbalanced, resembling a linked list, leading to a time complexity of O(n) for search operations.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of the inorder traversal of a binary tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
Inorder traversal visits each node exactly once, resulting in a time complexity of O(n), where n is the number of nodes in the tree.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the worst-case time complexity of the depth-first search (DFS) algorithm on a binary tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
The worst-case time complexity of depth-first search (DFS) on a binary tree is O(n), where n is the number of nodes in the tree.
Correct Answer:
A
— O(n)
Learn More →
Showing 1 to 7 of 7 (1 Pages)