Data Structures & AlgorithmsHardTCS NQT · Infosys pattern

Undirected graph edges: E–C, C–A, B–E, B–C, A–B, A–E, C–D. Using a BFS 2-colouring, is this graph bipartite?

  1. A. Cannot be determined without edge weights
  2. B. Yes, it is bipartite
  3. C. Yes, but only if the graph is also a tree
  4. D. No, it contains an odd-length cycle

Correct answer: D. No, it contains an odd-length cycle

BFS 2-colouring assigns alternating colours level by level from any start vertex; the graph is bipartite exactly when no edge ever connects two same-coloured vertices, which happens exactly when the graph has no odd-length cycle. Here the colouring fails, so the answer is "No, it contains an odd-length cycle".

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic