Data Structures & AlgorithmsHardProduct-company placement
In the DAG with edges A→E, A→G, B→E, C→A, C→B, C→E, C→F, C→G, D→F, E→F, G→F, how many distinct directed paths are there from C to F, and how many edges does the longest one have?
- A. 6 paths, longest 2
- B. 7 paths, longest 3
- C. 6 paths, longest 3
- D. 5 paths, longest 3
Correct answer: C. 6 paths, longest 3
Process vertices in reverse topological order: paths(u) = Σ paths(v) over edges u→v with paths(F) = 1, giving 6; 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
- For the string PROPERTY, what are the lengths of the longest palindromic SUBSTRING and the longest palindromic SUBSEQUENCE?
- DFS runs on the directed graph with adjacency lists A: D; B: CF; C: AEG; D: –; E: ABG; F: D; G: F, starting at A, scanning lists in the…
- Symbols occur with frequencies 24, 26, 33, 34, 35, 38. How many bits does an optimal (Huffman) prefix code need for the whole message, and…
- A binary search tree holds exactly the keys 27, 34, 63, 64, 72, 73, 95, 99. Which ONE of the following can be its POSTORDER traversal?
- Five matrices have dimensions 5×5 , 5×5 , 5×15 , 15×4 , 4×3. What is the minimum number of scalar multiplications needed to compute their…
- The directed graph A→B (4), A→C (5), A→E (3), B→D (6), B→E (-3), C→E (7), D→C (1), E→D (2) has one negative edge but no negative cycle…