• edited by
26,938 views
51 51 votes

In an unweighted, undirected connected graph, the shortest path from a node $S$ to every other node is computed most efficiently, in terms of time complexity, by

  1. Dijkstra’s algorithm starting from $S$.

  2. Warshall’s algorithm.

  3. Performing a DFS starting from $S$.

  4. Performing a BFS starting from $S$.

5 Answers

Best answer
69 69 votes

Dijkstra’s and Warshall's algorithms are used only for weighted graphs.

Both DFS and BFS can be used for finding path between $2$ vertices in undirected and unweighted graph but BFS can only give the shortest path as concerned in given question. So, BFS is answer.

Note :  Finding only path (DFS) and finding shortest path (BFS) matters a lot.
 
Must Read: https://www.quora.com/What-are-the-advantages-of-using-BFS-over-DFS-or-using-DFS-over-BFS-What-are-the-applications-and-downsides-of-each

Correct Answer: D.

• edited by
13 13 votes
In BFS traversal .1st we note those vertices which can be reached directly from starting vertex..next we note the vertices which can be reached in 2 steps from starting vertex ..then as follows so it is the best choice i can make
9 9 votes

 * Time Comlexity of the Dijkstra’s algorithm is O(|V|^2 + E) 
* Time Comlexity of the Warshall’s algorithm is O(|V|^3)
* DFS cannot be used for finding shortest paths
* BFS can be used for unweighted graphs. Time Complexity for BFS is O(|E| + |V|)

Answer D

3 3 votes

Dijkstra runs in O(E log V) time. //Time complexity is different when Data Structures used are different)

BFS runs in O(E + V) time. //adjacency list.

A BFS can be seen as a lightweight version of Dijkstra's algorithm, that can handle only unweighted graphs (or the graphs in which each edge weighs equally; same thing)

Option D


Other uses of BFS/DFS:-

  • Checking if the graph is connected. And, finding connected components — also can find the number of nodes in a connected component. It can also check if a graph is cyclic or acyclic. Also, for topological sorting. (DFS can do all this, too)
     
  • DFS can be used to find cut edges and vertices.
     
  • BFS can be used as a lightweight version of Dijkstra. It can also check if a graph is bipartite.
3 3 votes

Time Complexity of the Dijkstra’s algorithm : It depends on your implementation of Dijkstra's Algorithm. Simple algorithm is given below with Time complexity of O(V2). There are also some time-efficient Algorithms: Graph represented using adjacency list can be reduced to O(E log V) with the help of binary heap.

Time Complexity of the Warshall’s algorithm: O(n3). Warshall’s algorithm basically we are using to find all pair shortest path.

 DFS cannot be used for finding shortest paths.

Time Complexity for BFS : O(E+V)

Answer:
Position:
Show:

Related questions

30 30 votes
7 answers 7 answers
13.1k
13.1k views
pC asked Dec 21, 2015
13,116 views
Consider the DAG with $V = \{1,2,3,4,5,6\}$ shown below.Which of the following is not a topological ordering?$1$ $2$ $3$ $4$ $5$ $6$$1$ $3$ $2$ $4$ $5$ $6$$1$ $3$ $2$ $4$...
14 14 votes
3 answers 3 answers
7.2k
7.2k views
go_editor asked Jun 10, 2016
7,220 views
Djikstra’s algorithm is used toCreate LSAsFlood an internet with informationCalculate the routing tablesCreate a link state database
45 45 votes
6 answers 6 answers
19.1k
19.1k views
Ishrat Jahan asked Oct 29, 2014
19,077 views
Consider a weighted, undirected graph with positive edge weights and let $uv$ be an edge in the graph. It is known that the shortest path from the source vertex $s$ to $u...
93 93 votes
11 answers 11 answers
45.8k
45.8k views
Kathleen asked Sep 21, 2014
45,770 views
An array of $n$ numbers is given, where $n$ is an even number. The maximum as well as the minimum of these $n$ numbers needs to be determined. Which of the following is T...