Data Structures & AlgorithmsModerateCodeforces Div 2 C · GATE CS
A directed graph has the vertices E, H, L, M, Q, U and the arcs H→U, M→Q, U→H, U→Q, E→H, E→M, L→H. How many strongly connected components does it have (maximal sets in which every vertex can reach every other)?
- A. 6
- B. 5
- C. 1
- D. 2
Correct answer: B. 5
Mutual reachability splits the vertices into 5 classes, each a strongly connected component (single vertices count too). Weakly connected components give 1, and counting only components with at least two vertices gives 1.
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 directed graph has the vertices C, I, L, R, U and the arcs I→U, I→C, I→L, R→I, R→U, R→C, R→L, U→C, C→I, C→L, L→U. Count the directed…
- Grid with 3 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.G G.G. .... Each step, which is a move…
- Starting from the integer 6, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A connected undirected graph has the vertices D, L, Q, R, T, Y and the edges Y–D, Y–T, D–Q, D–R, D–L, R–T, R–L, T–L. Parallel edges are…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, with edges P4–Q2, P3–Q3, P4–Q3, P1–Q3, P2–Q1, P4–Q1. What is the…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 2) if n % 2 == 0: f(n - 3) How many times is f called in total…