Data Structures & AlgorithmsHardProduct-company placement
In the DAG with edges A→D, A→F, C→B, D→B, D→C, D→E, D→F, D→G, E→B, G→E, G→F, how many distinct directed paths are there from A to F, and how many edges does the longest one have?
- A. 3 paths, longest 3
- B. 3 paths, longest 2
- C. 4 paths, longest 3
- D. 2 paths, longest 3
Correct answer: A. 3 paths, longest 3
Process vertices in reverse topological order: paths(u) = Σ paths(v) over edges u→v with paths(F) = 1, giving 3; the same order with max(1 + len(v)) gives the longest path, 3 edges.
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, A–G, B–E, C–E, C–F, C–G, D–E, D–F, D–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…
- What is the length of the shortest string that has BOTH COMPUTER and SUBSEQUENT as subsequences (shortest common supersequence)?
- A rooted tree has 6 nodes with 1 child, 6 nodes with 2 children, 3 nodes with 3 children, and every other node is a leaf. How many leaves…
- Edit distance between HEAPSORT and DYNAMIC where insert and delete cost 1 each but a substitution costs 2: what is the minimum total cost?
- How many topological orderings does the DAG on vertices A–F with edges C→A, D→A, E→A, E→D, F→C, F→D, F→E have?
- An undirected connected graph has edges A–D, A–H, B–F, B–G, C–G, C–H, D–E, D–G, F–H, G–I. How many articulation points (cut vertices) and…