Data Structures & AlgorithmsHardGATE CS · ICPC regional · Product Company SDE
In the undirected graph with edges A–B:4, A–C:9, B–D:8, B–E:10, E–F:2, C–D:4, F–A:8, E–D:11, what is the shortest-path distance from A to C?
- A. 9
- B. 14
- C. 13
- D. 7
Correct answer: A. 9
Run Dijkstra from A: A=0, B=4, C=9, D=12, E=10, F=8. 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
- A forest has 27 vertices and 2 connected components (trees). How many edges does it have?
- Keys 12, 33, 64, 60, 24, 16, 31 are inserted one by one into an empty binary search tree. What is the pre-order traversal?
- Keys 76, 95, 23, 92, 94, 56, 15, 57, 87 are inserted in this order into an empty BST. How many leaf nodes does the tree have?
- An undirected graph has adjacency lists A:BC B:ADE C:ADE D:BC E:BC. Neighbours are always explored in alphabetical order. Which is the DFS…
- How many different spanning trees does the complete graph K7 have (Cayley's formula)?
- Keys 12, 98, 23, 44, 16, 38, 41, 70 are inserted one by one into an empty binary search tree. What is the post-order traversal?