Mykhailo Marufenko - 1 year ago 112

Python Question

There is question from one Quiz that I don't fully understand:

Suppose you have a weighted directed graph and want to find a path between nodes A and B with the smallest total weight. Select the most accurate statement:

- If some edges have negative weights, depth-first search finds a correct solution.
- If all edges have weight 2, depth-first search guarantees that the first path found to be is the shortest path.
- If some edges have negative weights, breadth-first search finds a correct solution.
- If all edges have weight 2, breadth-first search guarantees that the first path found to be is the shortest path.

Am I right that #1 is correct?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

4 is the correct one!, because all edges have the same weight, so you need to find the node traversing the minimum quantity of edges.

1 Is wrong because depth-first search doesn't consider edge weights, so any node could be reached first

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**