Q. Which traversal method is guaranteed to find the shortest path in an unweighted graph?
A.
Depth-First Search
B.
Breadth-First Search
C.
Dijkstra's Algorithm
D.
A* Search
Solution
BFS is guaranteed to find the shortest path in an unweighted graph because it explores all neighbors at the present depth prior to moving on to nodes at the next depth level.
Q. Which traversal method is more memory efficient for deep graphs?
A.
BFS
B.
DFS
C.
Both are equally efficient
D.
Neither is efficient
Solution
DFS can be more memory efficient for deep graphs because it only needs to store the current path from the root to the leaf, while BFS stores all nodes at the current level.
Q. Which traversal method is more memory efficient for large graphs?
A.
BFS
B.
DFS
C.
Both are equally efficient
D.
Neither is efficient
Solution
DFS can be more memory efficient than BFS for large graphs, as it uses a stack (or recursion) and does not need to store all the vertices at the current level.
Q. Which traversal method is more memory efficient for sparse graphs?
A.
BFS
B.
DFS
C.
Both are equal
D.
Neither is efficient
Solution
DFS is generally more memory efficient for sparse graphs as it can use less space compared to BFS, which needs to store all nodes at the current level.
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
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.
Q. Which traversal method is typically used for searching in a tree structure?
A.
BFS
B.
DFS
C.
Both BFS and DFS
D.
None of the above
Solution
Both BFS and DFS can be used for searching in a tree structure, depending on the specific requirements of the search (e.g., shortest path vs. exhaustive search).
Q. Which traversal method is typically used to find the shortest path in an unweighted graph?
A.
Depth-First Search
B.
Breadth-First Search
C.
Dijkstra's Algorithm
D.
A* Search
Solution
BFS is used to find the shortest path in an unweighted graph because it explores all neighbors at the present depth prior to moving on to nodes at the next depth level.
Q. Which traversal method is used to get the nodes of a binary tree in non-decreasing order?
A.
Pre-order
B.
Post-order
C.
In-order
D.
Level-order
Solution
In-order traversal visits the left subtree, the root, and then the right subtree, which results in nodes being accessed in non-decreasing order for binary search trees.
Q. Which traversal method of a binary tree can be used to retrieve nodes in non-decreasing order?
A.
Pre-order
B.
Post-order
C.
In-order
D.
Level-order
Solution
In-order traversal visits the left subtree, the root, and then the right subtree, which results in nodes being retrieved in non-decreasing order for binary search trees.
Q. Which traversal method of a binary tree visits nodes in the order of left child, root, right child?
A.
Pre-order
B.
In-order
C.
Post-order
D.
Level-order
Solution
In-order traversal visits the left child first, then the root, and finally the right child, which results in the nodes being visited in ascending order for a binary search tree.