Data Structures & AlgorithmsHardGATE CS · ICPC regional
Problem: How many simple cycles (cycles that visit no vertex twice, with 3 or more vertices) does the complete undirected graph K4 on vertices 1–4 contain?
- A. 4
- B. 14
- C. 10
- D. 7
Correct answer: D. 7
K4 has C(4, 3) = 4 triangles and (4 − 1)!/2 = 3 Hamiltonian 4-cycles, so 7 simple cycles. Counting triangles only gives 4, counting both directions of each cycle gives 14, and counting the 3! vertex orders of a 4-cycle without dividing by 2 gives 4 + 6 = 10.
More Coding Interview Problems questions
- Problem: A rooted tree (root 1) has children lists: 1: [2, 3], 2: [4, 5, 6], 3: [7], 4: [], 5: [8], 6: [], 7: [9], 8: [], 9: []. How many…
- Problem: For the same rooted tree as the previous question (root 1: children 2, 3; 2: children 4, 5, 6; 3: child 7; 5: child 8; 7: child…
- Problem: In a binary tree with 7 nodes in level order [10, 5, 15, 2, 7, 12, 20] (missing children are shown as absent, so the array…
- Problem: Three sorted rows are [1, 5, 9, 14], [2, 6, 10, 15] and [3, 7, 11, 16]. Merging all rows into one sorted sequence, what is the…
- Problem: What is the length of the longest substring of "abcabcbb" with all characters distinct?
- Problem: The shortest palindrome obtainable by inserting characters only at the front of "abacd" has what length?