IAE Academy

GATE 2023 CS Q.56: solution and answer

GATE 2023 · CSQ.56 · 2 marks · NAT

Let . Let denote the powerset of . Consider an undirected graph whose vertex set is . For any , is an edge in if and only if (i) , and (ii) either or . For any vertex in , the set of all possible orderings in which the vertices of can be visited in a Breadth First Search (BFS) starting from is denoted by .

If denotes the empty set, then the cardinality of is ______.

See the question in the paper

Answer and solution

ANSWER

The cardinality of , the set of distinct BFS visiting orders from , is .

Official answer: 5040Source: Official answer key, GATE 2023 CS (IIT Kanpur)

  1. U = {1,2,3}, so 2^U has 2^3 = 8 elements; G has 8 vertices, one per subset of U.

  2. Edge rule: A and B are adjacent in G iff one is a strict (proper) subset of the other — this is the FULL comparability relation of the subset partial order (any degree of nesting), not merely the Hasse-diagram cover edges.

  3. ∅ is a proper subset of every one of the other 7 (nonempty) subsets of U, so ∅ is adjacent, directly, to all 7 remaining vertices in G.

  4. Therefore a BFS starting at ∅ has exactly two levels: level 0 = {∅}, and level 1 = all 7 other vertices (each at distance 1) — there is no level 2, since every vertex is already reachable from ∅ in one step.

  5. BFS mechanics: after dequeuing ∅, the algorithm scans ∅'s neighbor list and enqueues its unvisited neighbors. Since neither the graph nor the BFS specification fixes the order same-level neighbors are discovered, any of the 7! orders in which the 7 neighbors get enqueued is a valid BFS execution.

  6. Once these 7 vertices are enqueued (in whichever order was chosen), dequeuing each in turn examines its own neighbors, but every vertex in G is already visited by that point, so no new vertex is discovered and the visiting order is not altered further — the final visiting order is exactly ∅ followed by the chosen permutation of the other 7.

  7. Hence the number of distinct BFS visiting sequences starting from ∅ equals the number of permutations of the remaining 7 vertices: 7!.

  8. 7! = 7×6×5×4×3×2×1 = 5040.

KEY IDEA

is a proper subset of every one of the other 7 subsets of , so in it is adjacent to all of them simultaneously. A BFS starting at therefore has only two levels: level 0 = and level 1 = all remaining 7 vertices. Since BFS's traversal order is not fixed for vertices within the same level (the specification leaves the order neighbors are discovered/enqueued unconstrained), every one of the permutations of the 7 level-1 vertices is a valid BFS visiting order following , and no further choices arise once they are enqueued (all vertices are already visited by then).

WATCH OUT FOR

Treating "adjacent iff proper subset" as only the Hasse-diagram cover relation (i.e., only edges to immediate subsets/supersets), which would make adjacent to just and force a multi-level BFS with far fewer orderings than . The problem states the FULL comparability relation ( or , any degree of nesting), not just cover edges, so is directly adjacent to all 7 other vertices.

From the GATE 2023 CS paper. Every question of this paper · Download the full paper · All 28 Graph algorithms questions, with notes

More Graph algorithms questions