Data Structures & AlgorithmsVery hardProduct-company placement
Undirected graph edges: D–A, D–B, A–C, B–C, A–B, D–C. Using a BFS 2-colouring, is this graph bipartite?
- A. Yes, it is bipartite
- B. Cannot be determined without edge weights
- C. No, it contains an odd-length cycle
- D. Yes, but only if the graph is also a tree
Correct answer: C. 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
- Keys 18, 24, 4, 33, 84, 49, 74, 69, 8, 79 are inserted via separate chaining (h(k) = k mod 8, new keys appended to the end of the chain)…
- Undirected graph edges: E–B, A–D, A–C, A–B, B–D. Using a BFS 2-colouring, is this graph bipartite?
- 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…