Data Structures & AlgorithmsHardICPC regional · GATE CS
Problem: On the complete graph K4 (vertices 0–3, every pair adjacent), how many walks of exactly 4 edges start at vertex 0? A walk may repeat vertices and edges, and reversing is allowed.
- A. 21
- B. 256
- C. 81
- D. 108
Correct answer: C. 81
Each step has 3 neighbours in K4, so 3⁴ = 81 walks. Those returning to 0 number 21, allowing self-loops gives 4⁴ = 256, and 4 · 3³ = 108 wrongly gives the first step 4 choices.
More Coding Interview Problems questions
- Problem: Lomuto partition uses the last element as the pivot on [3, 8, 2, 5, 1, 4, 7, 6]. After one partition pass, at what index…
- Problem: Five numbers 1, 2, 3, 4, 5 are inserted in that order into an initially empty min-heap (array form, sift-up after each…
- Problem: Binary search for the value 77 in the sorted list 1, 2, ..., 100 uses the midpoint mid = (lo + hi) // 2 and the inclusive range…
- Problem: What is the value of the lowest set bit of 96 (the largest power of 2 dividing 96)?
- Problem: For the numbers 1, 2, 3, 4, 5, how many unordered pairs (i, j) with i < j have i XOR j strictly less than 4?
- Problem: What is the sum of the proper divisors of 220 (divisors less than 220)?