Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
In the undirected graph with edges A–B:12, A–C:9, C–D:12, D–E:10, C–F:15, E–G:12, E–F:6, A–D:15, what is the shortest-path distance from A to F?
- A. 24
- B. 26
- C. 25
- D. 23
Correct answer: A. 24
Run Dijkstra from A: A=0, B=12, C=9, D=15, E=25, F=24, G=37. 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 82, 68, 95, 70, 94, 13, 69, 23, 56 are inserted in this order into an empty BST. How many leaf nodes does the resulting tree have?
- An undirected graph has adjacency lists A:BCF B:ADF C:AE D:B E:CF F:ABE. Neighbours are always explored in alphabetical order. Which is…
- In the undirected graph with edges A–B:12, B–C:8, B–D:12, A–E:9, D–F:10, B–F:14, A–C:12, what is the shortest-path distance from A to E?
- Keys 81, 18, 92, 48, 71, 55, 44, 41 are inserted in this order into an empty BST. What is the postorder traversal?
- A max-heap is built by inserting 55, 85, 57, 63, 32, 19, 91, 12 one by one (sift-up on each insert). After one extract-max (move the last…
- A max-heap is built by inserting 73, 97, 96, 27, 78, 89, 18 one by one (sift-up on each insert). After one extract-max (move the last…