Data Structures & AlgorithmsHardICPC regional · GATE CS
Problem: A set of 10 people is divided into 5 pairs. How many distinct ways are there to form these pairs (unordered pairs, unordered collection of pairs)?
- A. 113400
- B. 45
- C. 945
- D. 30240
Correct answer: C. 945
Perfect matchings of 10 people: 9 · 7 · 5 · 3 · 1 = 945 (= 10!/(2⁵ · 5!)). Not dividing by 5! gives 113400, one pair alone gives C(10,2) = 45, and 10!/5! = 30240 forgets the 2⁵.
More Coding Interview Problems questions
- Problem: In the array [5, 8, 3, 7, 2], find the second-largest element.
- Problem: A tree with 5 nodes is given by the parent array p = [−1, 0, 0, 1, 1] (node 0 is the root). How many leaves does it have?
- Problem: The bit pattern 10110 is shifted left by 2 positions and then XOR-ed with the original pattern. What is the decimal value of the…
- Problem: Vertices 0–4 have undirected edges 0-1 (3), 1-2 (1), 2-3 (4), 3-4 (2), 0-4 (6), 1-4 (5). A path's cost is the sum of its edge…
- Problem: A directed graph has vertices 0–3 with arcs 0→1, 1→2, 2→1, 2→3. Using DFS from vertex 0 with children visited in increasing…
- Problem: Tree with root 1 and children 1: [2, 3], 2: [4, 5], 4: [6]. What is the number of nodes in the subtree of node 2 (node 2 counts…