Q. What is the main difference between a binary tree and a binary search tree?
-
A.
Binary trees can have duplicate values, binary search trees cannot
-
B.
Binary search trees are always balanced, binary trees are not
-
C.
Binary search trees have a specific ordering property, binary trees do not
-
D.
There is no difference
Solution
A binary search tree has the property that for any node, all values in the left subtree are less and all values in the right subtree are greater.
Correct Answer:
C
— Binary search trees have a specific ordering property, binary trees do not
Learn More →
Q. What is the space complexity of a recursive implementation of binary tree traversal?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(1)
-
D.
O(n log n)
Solution
The space complexity is O(n) due to the recursion stack in the worst case, where n is the number of nodes in the tree.
Correct Answer:
A
— O(n)
Learn More →
Q. Which of the following is a valid way to implement a binary tree node in Python?
-
A.
class Node: def __init__(self, value): self.value = value
-
B.
class Node: def __init__(self, value): self.value = value; self.left = None; self.right = None
-
C.
class Node: def __init__(self): self.value = None
-
D.
class Node: def __init__(self, value): self.left = None; self.right = None
Solution
A valid binary tree node implementation includes left and right pointers, allowing for the structure of a binary tree.
Correct Answer:
B
— class Node: def __init__(self, value): self.value = value; self.left = None; self.right = None
Learn More →
Q. Which of the following is true about the height of a binary tree?
-
A.
Height is the number of nodes in the longest path from root to leaf
-
B.
Height is the number of edges in the longest path from root to leaf
-
C.
Height is always equal to the number of levels in the tree
-
D.
Height can be negative
Solution
The height of a binary tree is defined as the number of edges in the longest path from the root to a leaf node.
Correct Answer:
B
— Height is the number of edges in the longest path from root to leaf
Learn More →
Q. Which traversal method would you use to get the nodes of a binary tree in pre-order?
-
A.
Visit left, visit right, visit node
-
B.
Visit node, visit left, visit right
-
C.
Visit right, visit left, visit node
-
D.
Visit node, visit right, visit left
Solution
Pre-order traversal visits the node first, then the left subtree, and finally the right subtree.
Correct Answer:
B
— Visit node, visit left, visit right
Learn More →
Showing 1 to 5 of 5 (1 Pages)