Data Structures & AlgorithmsHardGATE CS
Dijkstra's algorithm runs from A on the directed graph A→B (15), A→C (3), A→D (13), C→B (9), D→C (4), D→E (1), D→F (10), E→B (12), E→C (13), E→F (5), F→A (11). In what order are the vertices finalised (removed from the priority queue)?
- A. A B C D E F
- B. A C B D E F
- C. A C D E F B
- D. A C D B E F
Correct answer: B. A C B D E F
Vertices leave the queue in increasing final distance: A=0, C=3, B=12, D=13, E=14, F=19. 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
- Using parts 2, 3, 5 (each any number of times), in how many ways can 11 be written as an ORDERED sum (so 1 + 2 and 2 + 1 count separately)?
- How many subsets of {1, 6, 7, 8, 11, 13, 14} have sum exactly 28?
- A DAG on vertices A–G has edges A→C, A→E, A→G, D→C, E→B, F→A, F→E, F→G. What order does Kahn's algorithm with a FIFO queue (initial zero…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 139 nodes. How many…
- A binary tree with distinct labels has INORDER E G A D B H C F I and LEVEL-ORDER D E I A F G H B C. What is its postorder traversal?
- A tree on vertices 1–11 has edges 2–1, 3–2, 4–1, 5–2, 6–3, 7–4, 8–6, 9–8, 10–8, 11–8. What is the size of a maximum independent set (no…