95.8k views
5 votes
Consider the algorithm that computes the shortest paths from one start node to all the other nodes in a weighted graph. Which one of the following best describes its running time?

a) O(m + n)
b) O(n log m)
c) O(m log n)
d) O(mn)

User Cassandre
by
8.4k points

1 Answer

2 votes

Final answer:

The running time of the algorithm that computes shortest paths in a weighted graph is O((m + n) log n).

Step-by-step explanation:

The algorithm that computes the shortest paths from one start node to all the other nodes in a weighted graph is known as Dijkstra's algorithm. It works by maintaining a set of explored nodes and iteratively updating the distance to each node until the shortest paths are found.

The running time of Dijkstra's algorithm can be represented as O((m + n) log n), where m is the number of edges and n is the number of nodes in the graph. This is because the algorithm uses a priority queue to efficiently select the next node to explore, and updating the distances in the queue takes O(log n) time.

Therefore, the correct option is b) O(n log m).

User Prateik Darji
by
8.5k points