Data Structures & AlgorithmsModerateGATE CS · ICPC regional
Problem: How many spanning trees does the cycle graph C5 (5 vertices in one cycle) have?
- A. 6
- B. 5
- C. 4
- D. 7
Correct answer: B. 5
A spanning tree of an n-cycle deletes exactly one edge, so the count equals the number of edges of the cycle. Counting subsets of three edges or all vertex subsets answers different questions.
More Coding Interview Problems questions
- Problem: A directed graph on vertices 0–5 has arcs 0→1, 1→2, 2→0, 2→3, 3→4, 4→3, 4→5, 5→1. How many vertices have in-degree equal to…
- Problem: On the undirected graph with edges 0-1 (4), 0-2 (1), 2-1 (2), 1-3 (5), 2-3 (9), 3-4 (3), find the minimum number of edges used by…
- Problem: The rooted tree (root 1) has children 1: [2, 3], 2: [4, 5], 3: [6], 4: [7], 6: [8]. How many nodes have a depth divisible by 3…
- Problem: In the string "abcbaxyzzyx", count the palindromic substrings of length exactly 5.
- Problem: How many adjacent positions i (0 ≤ i < n−1) of "abbaabab" form the pair "ab" or the pair "ba"?
- Problem: How many indices i satisfy s[i] = s[i+2] in the string "abcabcab" (0 ≤ i ≤ n−3)?