Data Structures & AlgorithmsHardGATE CS · Product Company SDE
Problem: The number of spanning trees of the complete graph K4 (4 labelled vertices, every pair joined by an edge) is what value? (Cayley's formula n^(n−2) may be used as a check.)
- A. 20
- B. 64
- C. 16
- D. 12
Correct answer: C. 16
Cayley's formula gives 4^(4−2) = 16; equivalently, of the C(6, 3) = 20 three-edge subsets, the 4 triangles are not trees. Counting every 3-edge subset gives 20, using n^(n−1) gives 64, and counting Hamiltonian paths only (4!/2) gives 12.
More Coding Interview Problems questions
- Problem: A graph on vertices 0–6 has edges 0-1, 0-2, 1-3, 2-3, 3-4, 4-5, 5-6, 4-6. Count the bridges (edges whose removal increases the…
- Problem: Maximum bipartite matching is computed for left side {A, B, C, D} and right side {1, 2, 3, 4} with allowed pairs: A–1, A–2, B–2…
- Problem: A tree has 8 nodes numbered 1–8 with edges 1-2, 1-3, 2-4, 2-5, 3-6, 3-7, 7-8. What is the size of a minimum vertex cover (a…
- Problem: In the directed graph on vertices 1–6 with arcs 1→2, 1→3, 2→4, 3→4, 4→5, 3→6, 6→5, what is the length of the longest directed…
- Problem: A binary tree is given in preorder (root first, then left subtree, then right subtree) as 8, 3, 1, 6, 4, 7, 10, 14, 13 and…
- Problem: For the binary tree with root value 2 and children: 2 has left child 3 and right child 9; 3 has left child 1 and right child 5; 9…