Q. In a binary tree, if a node has only one child, which traversal will still visit all nodes?
-
A.
In-order
-
B.
Pre-order
-
C.
Post-order
-
D.
All of the above
Solution
All traversal methods (in-order, pre-order, post-order) will visit all nodes even if a node has only one child.
Correct Answer:
D
— All of the above
Learn More →
Q. In a binary tree, what does the term 'leaf node' refer to?
-
A.
A node with two children
-
B.
A node with one child
-
C.
A node with no children
-
D.
A node that is the root
Solution
A leaf node is defined as a node that has no children.
Correct Answer:
C
— A node with no children
Learn More →
Q. In a binary tree, what is the time complexity of searching for an element in the worst case?
-
A.
O(log n)
-
B.
O(n)
-
C.
O(n log n)
-
D.
O(1)
Solution
In the worst case, searching for an element in a binary tree can take O(n) time, especially if the tree is unbalanced.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the result of an inorder traversal of a binary search tree?
-
A.
Sorted order of elements
-
B.
Reverse sorted order of elements
-
C.
Random order of elements
-
D.
Level order of elements
Solution
An inorder traversal of a binary search tree results in the elements being visited in sorted order.
Correct Answer:
A
— Sorted order of elements
Learn More →
Q. What is the time complexity of inserting a node in a balanced binary search tree?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
In a balanced binary search tree, the time complexity for inserting a node is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. Which of the following is NOT a characteristic of a binary tree?
-
A.
Each node has at most two children
-
B.
It can be empty
-
C.
All nodes have the same number of children
-
D.
It has a root node
Solution
In a binary tree, not all nodes have to have the same number of children; some can have zero, one, or two children.
Correct Answer:
C
— All nodes have the same number of children
Learn More →
Showing 1 to 6 of 6 (1 Pages)