Data Structures & AlgorithmsHardGATE CS · ICPC regional · Product Company SDE
In the undirected graph with edges A–B:2, A–C:3, A–D:5, C–E:3, E–F:8, F–A:2, what is the shortest-path distance from A to B?
- A. 3
- B. 0
- C. 2
- D. 6
Correct answer: C. 2
Run Dijkstra from A: A=0, B=2, C=3, D=5, E=6, F=2. The fewest-edge path (BFS) is not necessarily the lightest.
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
- An undirected graph has adjacency lists A:BCDF B:AC C:AB D:AE E:D F:A. Neighbours are always explored in alphabetical order. Which is the…
- Keys 37, 18, 57, 76, 72, 36, 64, 21 are inserted in this order into an empty BST. What is the height of the tree (edges on the longest…
- A max-heap is built by inserting 61, 86, 95, 83, 45, 47, 46 one by one. After a single extract-max (move last element to root, sift-down)…
- An undirected graph has edges (u–v: weight) A–B:30, A–C:9, A–D:11, D–E:14, A–E:25. What is the weight of its minimum spanning tree?
- Directed edges: A→B (6), A→C (6), C→B (-2), B→D (3). Dijkstra's algorithm, which finalises each vertex once when it is removed from the…
- Keys 8, 91, 32, 54, 14, 31, 17, 21, 26 are inserted via separate chaining (h(k) = k mod 5, new keys appended to the end of the chain) into…