Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern
A directed graph has weighted edges A→B (4), A→C (1), C→B (2), B→D (1), C→D (5), D→E (3). Dijkstra's algorithm is run from A. What is the shortest distance to E?
- A. 8
- B. 7
- C. 4
- D. 16
Correct answer: B. 7
A→C = 1, then C→B makes B = 3 (better than 4), B→D makes D = 4 (better than 1 + 5 = 6), and D→E makes E = 7. Keeping the direct A→B edge gives 8, 4 is the distance to D, not E, and 16 adds every edge weight.
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 edges A–B (2), A–C (3), B–C (1), B–D (4), C–D (5), C–E (6), D–E (2). What is the total weight of its minimum…
- A DAG has edges A→B, A→C, B→D, C→D, D→E. How many different topological orderings does it have?
- How many structurally different binary search trees can be built from 4 distinct keys?
- Using the master theorem, what is the solution of T(n) = 4T(n/2) + n²?
- What is the solution of T(n) = T(n/3) + T(2n/3) + n?
- What is the length of the longest common subsequence of ALGORITHM and LOGARITHM?