Data Structures & AlgorithmsHardGATE CS
Dijkstra's algorithm runs from A on the directed graph A→B (14), A→F (2), C→A (12), C→E (7), C→F (2), D→B (7), D→C (5), D→E (3), E→F (6), F→B (3), F→D (13). In what order are the vertices finalised (removed from the priority queue)?
- A. A B F D C E
- B. A F C B D E
- C. A F B C D E
- D. A F B D E C
Correct answer: D. A F B D E C
Vertices leave the queue in increasing final distance: A=0, F=2, B=5, D=15, E=18, C=20. Ordering by hop count, by Prim-style cheapest edge, or by the direct edge from A ignores cheaper multi-edge routes.
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
- All suffixes of the string 'abcab' are inserted into a character trie (a suffix trie). How many nodes does it have, including the root?
- Six sorted files have 27, 35, 38, 45, 52, 54 records. Merging two files of sizes a and b costs a + b. What is the minimum total cost to…
- What is the minimum number of edges that must be deleted from the undirected graph with edges A–B, B–C, B–E, B–F, C–D, C–E, C–F, D–F, E–F…
- What does f(3) print? c void f(int n) { if (n <= 0) return; printf("%d", n); f(n - 2); printf("%d", n); f(n - 1); }
- All suffixes of the string 'mississ' are inserted into a character trie (a suffix trie). How many nodes does it have, including the root?
- Keys 14, 86, 32, 49, 38, 76, 17, 91, 35, 81, 16 are inserted in that order into an empty BST. Then 32 is deleted and after that 86 is…