Data Structures & AlgorithmsVery hardProduct-company placement
Undirected graph edges: E–B, A–D, A–C, A–B, B–D. Using a BFS 2-colouring, is this graph bipartite?
- A. Yes, but only if the graph is also a tree
- B. No, it contains an odd-length cycle
- C. Yes, it is bipartite
- D. Cannot be determined without edge weights
Correct answer: B. 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".
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A directed graph has edges C→A, B→D, D→B, D→C, D→A. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a cycle), does…
- A directed graph has edges A→B, C→D, D→C, C→B. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a cycle), does this…
- Build a binary min-heap in place from the array [73, 61, 88, 9, 29, 24, 58, 42] using bottom-up heapify (sift-down from the last internal…
- A directed graph has edges D→B, C→D, A→B, D→C. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a cycle), does this…
- A disjoint-set (union-find with union by rank and path compression) over 7 elements (0 to 6), each initially its own component, runs this…
- A disjoint-set (union-find with union by rank and path compression) over 8 elements (0 to 7), each initially its own component, runs this…