Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A tree on the vertices D, E, F, I, L, Q, Y, Z has the arcs E→Y, F→Y, Z→Y, Z→L, Q→Z, D→Y, I→D (each undirected edge is directed as shown). You may reverse the direction of some arcs. What is the minimum number of arcs to reverse so that every vertex can be reached from E?
- A. 5
- B. 4
- C. 6
- D. 7
Correct answer: A. 5
In a tree, each edge must point from the parent towards the child (away from the root); an edge pointing towards the root must be reversed. Brute force over reversal sets confirms 5. Counting the arcs that already point away gives 2, which is the wrong quantity.
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 connected undirected graph has the vertices B, E, F, O, Q and weighted edges (weights in brackets): B–O (11), F–O (10), B–Q (13), Q–E…
- An undirected graph has the vertices F, J, M, N, T, W and the edges J–F, J–W, J–T, F–W, N–T, W–M, W–T, M–T. What is its chromatic number…
- A directed acyclic graph has the vertices B, F, M, Q, R, V, W, X and the directed edges F→M, B→F, W→M, V→R, M→Q, F→Q, V→Q, B→V, B→X, B→R…
- A tree has vertices with values in brackets: B[8], C[0], L[-3], G[-1], N[3], V[5]. The edges are B–C, B–L, C–G, G–N, B–V. A path is any…
- On an 6×6 chessboard, rows and columns are numbered 0 to 5, and squares are written (row, column). A knight moves in the usual L-shape…
- The directed acyclic graph has the vertices C, E, J, K, L, M, Q, Z and the arcs Q→C, Q→M, C→J, L→J, L→K, Q→K, E→J, M→C, M→L, M→E, Q→E…