## Graph Shortest Paths

Question 1 |

Consider the directed graph shown in the figure below. There are multiple shortest paths between vertices S and T. Which one will be reported by Dijstra?s shortest path algorithm? Assume that, in any iteration, the shortest path to a vertex v is updated only when a strictly shorter path to v is discovered.

SDT | |

SBDT | |

SACDT | |

SACET |

**Graph Shortest Paths**

**Discuss it**

Question 1 Explanation:

See Dijkstra’s shortest path algorithm
When the algorithm reaches vertex 'C', the distance values of 'D' and 'E' would be 7 and 6 respectively. So the next picked vertex would be 'E'

Question 2 |

To implement Dijkstra’s shortest path algorithm on unweighted graphs so that it runs in linear time, the data structure to be used is:

Queue | |

Stack | |

Heap | |

B-Tree |

**Graph Shortest Paths**

**Discuss it**

Question 2 Explanation:

The shortest path in an un-weighted graph means the smallest number of edges that must be traversed in order to reach the destination in the graph. This is the same problem as solving the weighted version where all the weights happen to be 1. If we use Queue (FIFO) instead of Priority Queue (Min Heap), we get the shortest path in linear time O(|V| + |E|). Basically we do BFS traversal of the graph to get the shortest paths.

Question 3 |

Dijkstra’s single source shortest path algorithm when run from vertex a in the below graph, computes the correct shortest path distance to

only vertex a | |

only vertices a, e, f, g, h | |

only vertices a, b, c, d | |

all the vertices |

**Graph Shortest Paths**

**Discuss it**

Question 3 Explanation:

Dijkstra’s single source shortest path is not guaranteed to work for graphs with negative weight edges, but it works for the given graph.
Let us see...
Let us run the 1st pass
b 1
b is minimum, so shortest distance to b is 1.
After 1st pass, distances are
c 3, e -2.
e is minimum, so shortest distance to e is -2
After 2nd pass, distances are
c 3, f 0.
f is minimum, so shortest distance to f is 0
After 3rd pass, distances are
c 3, g 3.
Both are same, let us take g. so shortest distance to g is 3.
After 4th pass, distances are
c 3, h 5
c is minimum, so shortest distance to c is 3
After 5th pass, distances are
h -2
h is minimum, so shortest distance to h is -2

Question 4 |

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

Dijkstra’s algorithm starting from S. | |

Warshall’s algorithm | |

Performing a DFS starting from S. | |

Performing a BFS starting from S. |

**Graph Shortest Paths**

**Discuss it**

Question 4 Explanation:

* 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|)

Question 5 |

Suppose we run Dijkstra’s single source shortest-path algorithm on the following edge weighted directed graph with vertex P as the source. In what order do the nodes get included into the set of vertices for which the shortest path distances are finalized? (GATE CS 2004)

P, Q, R, S, T, U | |

P, Q, R, U, S, T | |

P, Q, R, U, T, S | |

P, Q, T, R, U, S |

**Graph Shortest Paths**

**Discuss it**

Question 5 Explanation:

Question 6 |

What is the time complexity of Bellman-Ford single-source shortest path algorithm on a complete graph of n vertices?
(A)
(B)
(C)
(D)

A | |

B | |

C | |

D |

**Graph Shortest Paths**

**Discuss it**

Question 6 Explanation:

Time complexity of Bellman-Ford algorithm is [Tex]\Theta(VE)[/Tex] where V is number of vertices and E is number edges (See this). If the graph is complete, the value of E becomes [Tex]\Theta(V^2)[/Tex]. So overall time complexity becomes [Tex]\Theta(V^3)[/Tex]

Question 7 |

In a weighted graph, assume that the shortest path from a source 's' to a destination 't' is correctly calculated using a shortest path algorithm. Is the following statement true?
If we increase weight of every edge by 1, the shortest path always remains same.

Yes | |

No |

**Graph Shortest Paths**

**Discuss it**

Question 7 Explanation:

See the following counterexample.
There are 4 edges s-a, a-b, b-t and s-t of wights 1, 1, 1 and 4 respectively. The shortest path from s to t is s-a, a-b, b-t. IF we increase weight of every edge by 1, the shortest path changes to s-t.

1 1 1 s-----a-----b-----t \ / \ / \______/ 4

Question 8 |

Following statement is true or false?

If we make following changes to Dijkstra, then it can be used to find the longest simple path, assume that the graph is acyclic. 1) Initialize all distances as minus infinite instead of plus infinite. 2) Modify the relax condition in Dijkstra's algorithm to update distance of an adjacent v of the currently considered vertex u only if "dist[u]+graph[u][v] > dist[v]". In shortest path algo, the sign is opposite.

True | |

False |

**Graph Shortest Paths**

**Discuss it**

Question 8 Explanation:

In shortest path algo, we pick the minimum distance vertex from the set of vertices for which distance is not finalized yet. And we finalize the distance of the minimum distance vertex.
For maximum distance problem, we cannot finalize the distance because there can be a longer path through not yet finalized vertices.

Question 9 |

Which of the following algorithm can be used to

**efficiently**calculate single source shortest paths in a Directed Acyclic Graph?Dijkstra | |

Bellman-Ford | |

Topological Sort | |

Strongly Connected Component |

**Graph Shortest Paths**

**Discuss it**

Question 9 Explanation:

Using Topological Sort, we can find single source shortest paths in O(V+E) time which is the most efficient algorithm. See following for details.
Shortest Path in Directed Acyclic Graph

Question 10 |

Given a directed graph where weight of every edge is same, we can efficiently find shortest path from a given source to destination using?

Breadth First Traversal | |

Dijkstra's Shortest Path Algorithm | |

Neither Breadth First Traversal nor Dijkstra's algorithm can be used | |

Depth First Search |

**Graph Shortest Paths**

**Discuss it**

Question 10 Explanation:

With BFS, we first find explore vertices at one edge distance, then all vertices at 2 edge distance, and so on.

There are 23 questions to complete.