Data Structures & AlgorithmsModerateInfosys · Cognizant pattern
Dijkstra's algorithm runs from S on the directed graph S→A (7), S→B (2), B→A (3), B→C (8), A→C (1), A→D (6), C→D (2). In what order are vertices finalised (removed from the priority queue)?
- A. S, B, A, C, D (D = 8)
- B. S, B, A, D, C (D = 11)
- C. S, A, B, C, D (D = 10)
- D. S, B, C, A, D (D = 8)
Correct answer: A. S, B, A, C, D (D = 8)
S(0) → B(2): relax A to 5, C to 10. A(5) → C becomes 6, D becomes 11. C(6) → D becomes 8. D(8). Order S, B, A, C, D with dist(D) = 8 via S → B → A → C → D. Taking S→A (7) directly misses the cheaper route through B.
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
- What is the maximum number of edges in a directed ACYCLIC graph with 6 vertices (no parallel edges)?
- What is the length of the longest common subsequence of PLACEMENT and COMPLETE?
- Keys 15, 10, 20, 8, 12, 25, 6, 11, 13, 9 are inserted into an empty BST. What is the height of the tree (edges on the longest root-to-leaf…
- Keys 10, 20, 30, 25, 28 are inserted into an empty AVL tree. Which rotations are performed, in order (named by imbalance case)?
- Floyd–Warshall on vertices 0–3 starts from the weight matrix below (∞ = no edge). After the iteration with k = 0 (paths allowed to go…
- How many distinct spanning trees does the graph with vertices A, B, C, D and edges A–B, B–C, C–D, D–A, A–C (a 4-cycle plus one diagonal)…