Data Structures & AlgorithmsVery hardGATE CSE · Advanced
The Floyd-Warshall algorithm runs on the 4-vertex directed graph with weights 1->2: 3, 1->4: 7, 2->1: 8, 2->3: 2, 3->1: 5, 3->4: 1, 4->1: 2 (no other edges). After the iterations using intermediate vertices 1 and 2 only, what is the entry D[2][4]?
- A. 3
- B. 15
- C. 17
- D. infinity
Correct answer: B. 15
Initially D[2][4] is infinite; through vertex 1 it becomes 8 + 7 = 15 and vertex 2 does not improve it (the better route via vertex 3 comes in the third iteration, giving 3).
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A weighted graph has vertices A, B, C, D and edges A-B 1, B-C 1, C-A 1, C-D 2, B-D 2, A-D 2. How many distinct minimum spanning trees does…
- A weighted tree has edges A-B 3, A-C 4, B-D 5, B-E 2, C-F 6, F-G 1, F-H 7, E-I 8, D-J 2, H-K 3. What is its diameter (the greatest path…
- Which traversal of a binary search tree visits the keys in ascending order?
- Which data structure does breadth-first search (BFS) use to decide which vertex to visit next?
- How many edges does a tree with n vertices have?
- In a min-heap, where is the smallest element always found?