Q. How do you determine the height of a binary tree?
A.
Count the number of nodes
B.
Count the number of edges
C.
Maximum depth of any node
D.
Minimum depth of any node
Show solution
Solution
The height of a binary tree is defined as the maximum depth of any node, which is the longest path from the root to a leaf.
Correct Answer:
C
— Maximum depth of any node
Learn More →
Q. In a binary tree, what does the term 'height' refer to?
A.
Number of nodes
B.
Number of edges
C.
Maximum depth of a node
D.
Minimum depth of a node
Show solution
Solution
The height of a binary tree is defined as the maximum depth of any node, which is the longest path from the root to a leaf.
Correct Answer:
C
— Maximum depth of a node
Learn More →
Q. What is the postorder traversal sequence of a binary tree with root A, left child B, and right child C?
A.
A B C
B.
B A C
C.
B C A
D.
C B A
Show solution
Solution
In postorder traversal, the sequence is left subtree, right subtree, and then the root. Thus, for the given tree, the sequence is B C A.
Correct Answer:
C
— B C A
Learn More →
Q. What is the primary purpose of a binary tree's inorder traversal?
A.
To delete nodes
B.
To find the height
C.
To sort the elements
D.
To count nodes
Show solution
Solution
The primary purpose of inorder traversal in a binary search tree is to retrieve the elements in sorted order.
Correct Answer:
C
— To sort the elements
Learn More →
Q. What is the primary use of a queue in tree traversal?
A.
To store nodes for depth-first search
B.
To store nodes for breadth-first search
C.
To store nodes for sorting
D.
To store nodes for searching
Show solution
Solution
A queue is primarily used in breadth-first search (level order traversal) to keep track of nodes to be visited next.
Correct Answer:
B
— To store nodes for breadth-first search
Learn More →
Q. What is the result of a postorder traversal on a binary tree?
A.
Root, Left, Right
B.
Left, Right, Root
C.
Right, Left, Root
D.
Left, Root, Right
Show solution
Solution
Postorder traversal visits nodes in the order: Left, Right, Root.
Correct Answer:
B
— Left, Right, Root
Learn More →
Q. What is the space complexity of recursive tree traversals?
A.
O(n)
B.
O(log n)
C.
O(1)
D.
O(n log n)
Show solution
Solution
The space complexity of recursive tree traversals 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 balanced trees, it is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. Which of the following is a valid way to implement a binary tree in C++?
A.
Using an array
B.
Using a linked list
C.
Using a struct
D.
All of the above
Show solution
Solution
A binary tree can be implemented using an array, a linked list, or a struct in C++. Each method has its own advantages and use cases.
Correct Answer:
D
— All of the above
Learn More →
Q. Which of the following is true about a binary search tree (BST)?
A.
Inorder traversal gives sorted order
B.
Preorder traversal gives sorted order
C.
Postorder traversal gives sorted order
D.
Level order traversal gives sorted order
Show solution
Solution
In a binary search tree, an inorder traversal visits nodes in non-decreasing order, thus giving a sorted order.
Correct Answer:
A
— Inorder traversal gives sorted order
Learn More →
Q. Which traversal method is not suitable for binary search trees when you want to delete nodes?
A.
Inorder
B.
Preorder
C.
Postorder
D.
Level order
Show solution
Solution
Preorder traversal is not suitable for deleting nodes in a binary search tree because it visits the root before its children, which can lead to incorrect deletions.
Correct Answer:
B
— Preorder
Learn More →
Q. Which traversal method uses a stack to keep track of nodes?
A.
Inorder
B.
Postorder
C.
Level order
D.
Preorder
Show solution
Solution
Preorder traversal can be implemented using a stack to keep track of nodes as we visit them in the order: root, left, right.
Correct Answer:
D
— Preorder
Learn More →
Showing 1 to 11 of 11 (1 Pages)