When is breadth-first search is optimal? A. When there is less number of nodes B. When all step costs are equal C. When all step costs are unequal D. None of the mentioned

[amp_mcq option1=”When there is less number of nodes” option2=”When all step costs are equal” option3=”When all step costs are unequal” option4=”None of the mentioned” correct=”option1″]

Breadth-first search (BFS) is an algorithm for traversing a graph. It starts at a given node and explores all of the node’s neighbors before moving on to any other nodes. This process continues until all of the nodes in the graph have been visited.

BFS is an optimal algorithm for finding the shortest path between two nodes in a graph when all of the step costs are equal. This is because BFS always explores the nodes in the order of their distance from the starting node.

However, BFS is not always an optimal algorithm when the step costs are unequal. In this case, it is possible that a different algorithm, such as Dijkstra’s algorithm, could find a shorter path.

Therefore, the correct answer to the question “When is breadth-first search is optimal?” is:

  • When all step costs are equal.

The other options are incorrect because they do not guarantee that BFS will find the shortest path.