IAE Academy

GATE 2018 CS Q.43: solution and answer

GATE 2018 · CSQ.43 · 2 marks · NAT

Let be a graph with vertices, with each vertex labelled by a distinct permutation of the numbers . There is an edge between vertices and if and only if the label of can be obtained by swapping two adjacent numbers in the label of . Let denote the degree of a vertex in , and denote the number of connected components in . Then, ______.

See the question in the paper

Answer and solution

ANSWER

Official answer: 109Source: Official answer key, GATE 2018 CS (IIT Guwahati)

  1. Each vertex is a permutation of . Two vertices are joined exactly when one label comes from the other by swapping two adjacent numbers (two neighbouring positions).

  2. Degree: a label has pairs of neighbouring positions , for . Swapping the entries in positions and always gives a different permutation, because the two numbers are distinct. Two different position pairs give different results, because they change different positions. So each vertex has exactly neighbours, and .

  3. Components: any permutation can be sorted into by repeatedly swapping an adjacent out-of-order pair (bubble sort). Each such swap moves along an edge, and edges are undirected. So every vertex is joined by a path to the identity permutation.

  4. Every vertex lies in the same component as the identity permutation, so is connected and .

  5. Therefore .

KEY IDEA

The graph has one vertex per permutation of 100 numbers and joins two permutations that differ by one adjacent swap. Each vertex has one neighbour per neighbouring position pair, which gives 99. Adjacent swaps can sort any permutation (bubble sort), so the graph is connected.

WATCH OUT FOR

Using or as the degree. Only swaps of neighbouring positions count, so the degree is , not the number of all pairs of positions. Another slip is to think the graph splits by parity of permutation. An adjacent swap changes parity, so the edges join even and odd permutations, but the graph is still connected.

From the GATE 2018 CS paper. Every question of this paper · Download the full paper · All 14 Graph theory questions, with notes

More Graph theory questions