Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
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?
- A. 8
- B. 10
- C. 9
- D. 11
Correct answer: C. 9
Run Dijkstra from A: A=0, B=12, C=12, D=24, E=9, F=26. 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 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…
- A DAG has edges A→B, A→C, B→D, C→E, A→D, B→C. Using Kahn's algorithm (always picking the smallest-labelled vertex among those currently…
- What is the time complexity of searching for a word of length m in a trie that stores n words, independent of n?
- An undirected graph has adjacency lists A:BCEF B:AD C:ADF D:BCF E:A F:ACD. Neighbours are always explored in alphabetical order. Which is…