Data Structures & AlgorithmsHardGATE CS · ICPC regional · Product Company SDE
In the undirected graph with edges A–B:9, B–C:8, B–D:9, B–E:3, B–F:9, A–F:5, D–F:12, E–D:11, what is the shortest-path distance from A to F?
- A. 3
- B. 4
- C. 10
- D. 5
Correct answer: D. 5
Run Dijkstra from A: A=0, B=9, C=17, D=17, E=12, F=5. 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:BCE B:AD C:ADE D:BC E:AC. Neighbours are always explored in alphabetical order. Which is the DFS…
- Keys 97, 30, 61, 33, 46, 40, 51, 36, 31 are inserted one by one into an empty binary search tree. What is the level-order traversal?
- Keys 68, 35, 20, 76, 29, 93, 85, 49, 58 are inserted in this order into an empty BST. How many leaf nodes does the tree have?
- A max-heap is built by inserting 23, 22, 90, 96, 49, 39, 36 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:3, A–C:21, A–D:19, A–E:17, D–F:13, D–B:29, C–B:27, C–E:2. What is the weight of its…
- In the undirected graph with edges A–B:1, B–C:8, C–D:10, A–E:11, C–F:11, A–C:5, E–F:6, F–B:6, what is the shortest-path distance from A to…