Open In App

GATE | Gate IT 2005 | Question 15

Like Article
Like
Save
Share
Report

In the following table, the left column contains the names of standard graph algorithms and the right column contains the time complexities of the algorithms. Match each algorithm with its time complexity.

 1. Bellman-Ford algorithm
2. Kruskal’s algorithm
3. Floyd-Warshall algorithm
4. Topological sorting
 A : O ( m log n)
B : O (n3)
C : O (nm)
D : O (n + m)

 
(A) 1→ C, 2 → A, 3 → B, 4 → D
(B) 1→ B, 2 → D, 3 → C, 4 → A
(C) 1→ C, 2 → D, 3 → A, 4 → B
(D) 1→ B, 2 → A, 3 → C, 4 → D


Answer: (A)

Explanation:

  • Bellman-Ford algorithm: Time complexity: O(VE)
  • Kruskal’s algorithm:Time Complexity: O(ElogE) or O(ElogV). Sorting of edges takes O(ELogE) time. After sorting, we iterate through all edges and apply find-union algorithm. The find and union operations can take atmost O(LogV) time. So overall complexity is O(ELogE + ELogV) time. The value of E can be atmost V^2, so O(LogV) are O(LogE) same. Therefore, overall time complexity is O(ElogE) or O(ElogV)
  •  Floyd-Warshall algorithm: Time Complexity: O(V^3)
  •  Topological sorting: Time Complexity: The above algorithm is simply DFS with an extra stack. So time complexity is same as DFS which is O(V+E).


Quiz of this Question


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads