Q. In a binary search, if the middle element is greater than the target, which half of the array is searched next?
A.
Left half
B.
Right half
C.
Both halves
D.
None
Show solution
Solution
If the middle element is greater than the target, the left half of the array is searched next.
Correct Answer:
A
— Left half
Learn More →
Q. In a binary search, if the target is less than the mid value, what should be the next step?
A.
Search the right half
B.
Search the left half
C.
Return the mid index
D.
Increase the mid index
Show solution
Solution
If the target is less than the mid value, the search should continue in the left half of the array.
Correct Answer:
B
— Search the left half
Learn More →
Q. In a binary search, if the target value is not found, what will be the return value?
A.
-1
B.
0
C.
null
D.
the index of the closest value
Show solution
Solution
Typically, binary search returns -1 to indicate that the target value is not present in the array.
Correct Answer:
A
— -1
Learn More →
Q. In a binary search, if the target value is not present in the array, what will be the return value?
A.
-1
B.
0
C.
null
D.
the index of the closest value
Show solution
Solution
Typically, binary search returns -1 to indicate that the target value is not found in the array.
Correct Answer:
A
— -1
Learn More →
Q. In a binary tree, how many children can a node have?
Show solution
Solution
A binary tree node can have at most two children, typically referred to as the left child and the right child.
Correct Answer:
B
— 2
Learn More →
Q. In a binary tree, how many edges are there if there are n nodes?
Show solution
Solution
In a binary tree, the number of edges is always one less than the number of nodes, hence there are n-1 edges for n nodes.
Correct Answer:
A
— n-1
Learn More →
Q. In a binary tree, how many leaf nodes can there be at maximum if there are n internal nodes?
A.
n + 1
B.
n
C.
2n
D.
n - 1
Show solution
Solution
In a binary tree, the maximum number of leaf nodes is n + 1, where n is the number of internal nodes.
Correct Answer:
A
— n + 1
Learn More →
Q. In a binary tree, how many nodes can be at the maximum level 'h'?
A.
2^h
B.
2^(h+1)
C.
h^2
D.
h!
Show solution
Solution
The maximum number of nodes at level 'h' in a binary tree is 2^h, as each node can have two children.
Correct Answer:
A
— 2^h
Learn More →
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
Show solution
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, if a node has two children, how many leaf nodes can it have at maximum?
Show solution
Solution
If a node has two children, it can lead to a maximum of 3 leaf nodes in its subtree, assuming each child has at least one leaf.
Correct Answer:
C
— 3
Learn More →
Q. In a binary tree, if a node has two children, how many nodes are there in its subtree?
Show solution
Solution
If a node has two children, there are at least 3 nodes in its subtree (the node itself and its two children).
Correct Answer:
C
— 3
Learn More →
Q. In a binary tree, if a node has two children, how many nodes are there in the subtree rooted at that node?
Show solution
Solution
If a node has two children, there are 3 nodes in the subtree rooted at that node (the node itself and its two children).
Correct Answer:
C
— 3
Learn More →
Q. In a binary tree, if a node has two children, how many nodes can be at the next level?
Show solution
Solution
If a node has two children, it can lead to a maximum of 4 nodes at the next level (2 children for each of the 2 children).
Correct Answer:
D
— 4
Learn More →
Q. In a binary tree, if the in-order and post-order traversals are given, how can you reconstruct the tree?
A.
Using only in-order
B.
Using only post-order
C.
Using both in-order and post-order
D.
Using pre-order and in-order
Show solution
Solution
To reconstruct a binary tree, both in-order and post-order traversals are needed.
Correct Answer:
C
— Using both in-order and post-order
Learn More →
Q. In a binary tree, if the in-order traversal yields the sequence [D, B, E, A, F, C], what is the pre-order traversal?
A.
[A, B, D, E, C, F]
B.
[A, B, E, D, C, F]
C.
[A, C, B, D, E, F]
D.
[A, B, D, C, E, F]
Show solution
Solution
The pre-order traversal can be derived from the in-order traversal and the structure of the tree, yielding [A, B, D, E, C, F].
Correct Answer:
A
— [A, B, D, E, C, F]
Learn More →
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
Show solution
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. In a binary tree, what does a null left child indicate?
A.
The node is a leaf
B.
The node has only a right child
C.
The node has no children
D.
The node is the root
Show solution
Solution
A null left child indicates that the node is a leaf node, meaning it has no children.
Correct Answer:
A
— The node is a leaf
Learn More →
Q. In a binary tree, what does it mean if a node has both left and right children?
A.
It is a leaf node
B.
It is a full node
C.
It is a complete node
D.
It is a balanced node
Show solution
Solution
A node with both left and right children is referred to as a full node in the context of binary trees.
Correct Answer:
B
— It is a full node
Learn More →
Q. In a binary tree, what does it mean if a node has two children?
A.
It is a leaf node
B.
It is a full node
C.
It is a parent node
D.
It is a root node
Show solution
Solution
A node with two children is referred to as a full node, as it has both left and right children.
Correct Answer:
B
— It is a full 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. 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
Show solution
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 height of a tree with only one node?
A.
0
B.
1
C.
2
D.
Undefined
Show solution
Solution
The height of a tree with only one node is 0, as height is defined as the number of edges on the longest path from the root to a leaf.
Correct Answer:
A
— 0
Learn More →
Q. In a binary tree, what is the in-order traversal of the nodes?
A.
Visit left subtree, root, right subtree
B.
Visit root, left subtree, right subtree
C.
Visit left subtree, right subtree, root
D.
Visit right subtree, root, left subtree
Show solution
Solution
In in-order traversal, the nodes are visited in the order: left subtree, root, right subtree.
Correct Answer:
A
— Visit left subtree, root, right subtree
Learn More →
Q. In a binary tree, what is the in-order traversal of the tree with nodes 1, 2, 3?
A.
[1, 2, 3]
B.
[2, 1, 3]
C.
[1, 3, 2]
D.
[3, 2, 1]
Show solution
Solution
In-order traversal visits the left subtree, then the root, and then the right subtree. For a tree with nodes 1, 2, 3, the in-order traversal is [2, 1, 3].
Correct Answer:
B
— [2, 1, 3]
Learn More →
Q. In a binary tree, what is the in-order traversal of the tree with nodes A, B, C, D arranged as follows: A is the root, B is the left child of A, and C is the right child of A, with D as the left child of C?
A.
A, B, C, D
B.
B, A, D, C
C.
B, A, C, D
D.
B, D, A, C
Show solution
Solution
The in-order traversal visits the left subtree, then the root, and then the right subtree, resulting in B, A, C, D.
Correct Answer:
C
— B, A, C, D
Learn More →
Q. In a binary tree, what is the in-order traversal of the tree with nodes A, B, C?
A.
A, B, C
B.
B, A, C
C.
B, C, A
D.
C, B, A
Show solution
Solution
In in-order traversal, the left subtree is visited first, then the root, and finally the right subtree. For a tree with nodes A (root), B (left), and C (right), the traversal is B, A, C.
Correct Answer:
B
— B, A, C
Learn More →
Q. In a binary tree, what is the in-order traversal of the 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
Show solution
Solution
The in-order traversal visits the left child first, then the root, and finally the right child, resulting in 2, 1, 3.
Correct Answer:
B
— 2, 1, 3
Learn More →
Q. In a binary tree, what is the maximum height of a tree with n nodes?
A.
n
B.
n/2
C.
log n
D.
n-1
Show solution
Solution
The maximum height of a binary tree with n nodes occurs when the tree is skewed, resulting in a height of n-1.
Correct Answer:
D
— n-1
Learn More →
Q. In a binary tree, what is the maximum number of children a node can have?
A.
One
B.
Two
C.
Three
D.
Unlimited
Show solution
Solution
In a binary tree, each node can have at most two children, typically referred to as the left and right child.
Correct Answer:
B
— Two
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 →
Showing 181 to 210 of 3237 (108 Pages)