Q. In a binary tree, what does a level-order traversal use to keep track of nodes?
-
A.
Stack
-
B.
Queue
-
C.
Array
-
D.
Linked List
Solution
Level-order traversal uses a queue to keep track of nodes at each level as it processes them.
Correct Answer:
B
— Queue
Learn More →
Q. What is the maximum number of nodes at level 'h' in a binary tree?
-
A.
h
-
B.
2^h
-
C.
2^(h+1) - 1
-
D.
h^2
Solution
The maximum number of nodes at level 'h' in a binary tree is 2^h, where h is the height of the tree.
Correct Answer:
B
— 2^h
Learn More →
Q. What is the result of a post-order traversal on the following binary tree: A, B, C, D?
-
A.
A B C D
-
B.
D C B A
-
C.
B D C A
-
D.
C B D A
Solution
In post-order traversal, you visit the left subtree, then the right subtree, and finally the root. Thus, for the given tree, the result is D C B A.
Correct Answer:
B
— D C B A
Learn More →
Q. What is the result of a pre-order traversal of the binary tree with root 1, left child 2, and right child 3?
-
A.
1, 2, 3
-
B.
2, 1, 3
-
C.
3, 1, 2
-
D.
1, 3, 2
Solution
In pre-order traversal, the root is visited first, followed by the left subtree and then the right subtree, resulting in 1, 2, 3.
Correct Answer:
A
— 1, 2, 3
Learn More →
Q. Which of the following is a valid way to implement a binary tree node in C++?
-
A.
struct Node { int data; Node* left; Node* right; };
-
B.
class Node { int data; Node left; Node right; };
-
C.
struct Node { int data; Node left; Node right; };
-
D.
class Node { public: int data; Node* left; Node* right; };
Solution
The correct implementation uses pointers for left and right children, and the class should have public access for the members.
Correct Answer:
D
— class Node { public: int data; Node* left; Node* right; };
Learn More →
Q. Which of the following is NOT a valid way to implement a binary tree in C++?
-
A.
Using a struct with pointers
-
B.
Using an array
-
C.
Using a linked list
-
D.
Using a vector
Solution
While you can use arrays and vectors to represent binary trees, using a linked list is not a standard way to implement a binary tree.
Correct Answer:
C
— Using a linked list
Learn More →
Showing 1 to 6 of 6 (1 Pages)