Data Structures & AlgorithmsHardProduct-company placement
In the DAG with edges A→B, A→G, B→D, D→G, E→A, E→B, E→C, E→D, E→F, E→G, G→C, how many distinct directed paths are there from E to C, and how many edges does the longest one have?
- A. 6 paths, longest 4
- B. 7 paths, longest 5
- C. 6 paths, longest 5
- D. 5 paths, longest 5
Correct answer: C. 6 paths, longest 5
Process vertices in reverse topological order: paths(u) = Σ paths(v) over edges u→v with paths(C) = 1, giving 6; the same order with max(1 + len(v)) gives the longest path, 5 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
- A 5 × 5 grid is given row by row as .##.. / ..... / ....# / ...#. / .#... ('#' = wall). Moving one step up, down, left or right through…
- What is the minimum number of cuts needed to split 'madamimad' into pieces that are all palindromes?
- A binary min-heap is stored in a 0-indexed array [13, 33, 15, 35, 42, 23, 32]. Perform, in order: insert 6, delete-min, insert 60…
- The directed graph A→C (5), A→E (7), B→A (5), C→B (5), D→A (5), D→B (-6), E→C (9), E→D (7) has one negative edge but no negative cycle…
- Kruskal's algorithm runs on the weighted undirected graph A–C (29), A–F (19), A–G (2), B–D (8), B–G (25), C–G (14), D–F (1), E–F (11), E–G…
- How many structurally different binary trees with 5 nodes have height EXACTLY 3 (height = edges on the longest root-to-leaf path)?