Data Structures & AlgorithmsHardProduct-company MCQ pattern
A directed graph has edges 1→2, 2→3, 3→1, 3→4, 4→5, 5→6, 6→4, 6→7, 7→8. How many strongly connected components does it have?
- A. 8
- B. 2
- C. 4
- D. 3
Correct answer: C. 4
{1, 2, 3} and {4, 5, 6} are cycles, while 7 and 8 lie on no cycle and are components on their own: 4 SCCs. The edge 3→4 does not merge the two cycles because there is no way back from 4 to 3.
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 1–2, 2–3, 3–1, 3–4, 4–5, 5–6, 6–4, 6–7. How many articulation points (vertices whose removal disconnects the…
- What is the time complexity of g(n)? python def g(n): if n <= 1: return for i in range(n): pass # O(1) g(n // 2) g(n // 2) g(n // 2)
- How many of these statements about DFS are correct? (i) In DFS of an undirected graph, every non-tree edge is a back edge (there are no…
- Keys are inserted into an empty BST in the order 45, 15, 79, 90, 10, 55, 12, 20, 50. What is the postorder traversal? python def insert(t…
- For the same kind of BST, what is the height (edges on the longest root-to-leaf path) after inserting 1, 2, 3, 4, 5, 6, 7 in order, versus…
- A max-heap is built with heapify on the array below (0-based, children 2i+1 and 2i+2). What is the resulting array? python def sift(a, i…