Data Structures & AlgorithmsVery hardGATE CS · Advanced
Floyd-Warshall is run on a directed graph with vertices 1-6 and arcs (weights): 1→2 (9), 1→3 (8), 1→4 (8), 1→5 (1), 2→5 (3), 2→6 (8), 3→1 (4), 3→6 (8), 4→3 (4), 5→3 (6), 5→6 (2), 6→4 (6). Intermediate vertices are tried in the order k = 1, 2, 3, 4, 5, 6. What is the matrix entry d[1][6] immediately after the iteration k = 3 has finished?
- A. 18
- B. 17
- C. 16
- D. 3
Correct answer: C. 16
After iteration k the entry is the shortest path using only vertices 1..k as intermediates. After k = 3 the entry is 16; it is 17 after k = 2 and only reaches the true distance 3 at the end.
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 flow network has source S = A and sink T = G (vertices A–G) with arcs and capacities: A→D (1), A→E (6), A→G (6), B→C (2), B→E (5), C→F…
- How many structurally different binary search trees can be built on the keys 1, 2, ..., 8 (all distinct shapes, one per key set) whose…
- A rooted tree has the vertices A–M with root A, given by parents: A is the parent of B, B is the parent of C, B is the parent of D, B is…
- A weighted undirected graph on A–H has the edges (weights): A–D (16), A–E (22), A–F (26), A–G (5), A–H (4), B–C (9), B–H (23), C–D (13)…
- Keys 45, 25, 65, 15, 35, 55, 75, 30 are inserted in this order into an empty binary search tree. What is its postorder traversal?
- What is the maximum number of nodes in a binary tree of height 5, where the height is the number of edges on the longest root-to-leaf path?