Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE
In the undirected graph with edges A–B:13, B–C:6, C–D:4, B–E:7, E–F:2, A–G:14, C–E:7, A–D:8, what is the shortest-path distance from A to B?
- A. 12
- B. 13
- C. 14
- D. 15
Correct answer: B. 13
Run Dijkstra from A: A=0, B=13, C=12, D=8, E=19, F=21, G=14. 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
- Keys 44, 29, 51, 67, 19, 20, 60, 37, 16 are inserted in this order into an empty BST. What is the height of the tree (edges on the longest…
- An undirected graph has adjacency lists A:BDE B:AC C:BE D:AF E:ACF F:DE. Neighbours are always explored in alphabetical order. Which is…
- An undirected graph has adjacency lists A:BCDE B:AC C:ABE D:AG E:ACF F:EH G:DH H:FG. Neighbours are always explored in alphabetical order…
- A max-heap is built by inserting 23, 96, 77, 61, 84, 26, 70, 72 one by one (sift-up on each insert). After one extract-max (move the last…
- An undirected graph has edges (u–v: weight) A–B:9, A–C:14, A–D:11, A–E:8, C–E:2, B–D:9. What is the weight of its minimum spanning tree?
- A min-heap is built by inserting 66, 44, 32, 55, 85, 62 one by one (sift-up on each insert). After one extract-min (move the last element…