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?
- A. Cannot be determined without edge weights
- B. Yes, it is bipartite
- C. Yes, but only if the graph is also a tree
- 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".
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 trie is built from the words {cat, card, dot, den, deed, dog}. Using the trie (walk the prefix's characters, then count all words in the…
- An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [B, C, G]; B: [A, E, G]; C: [A, G]; D: [F, G]; E…
- 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…
- Keys 55, 65, 75 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Keys 4, 49, 97, 15, 7, 96, 24, 50 are inserted in this order into an empty BST. Using the BST-specific LCA algorithm (walk down from the…
- Keys 38, 28, 18 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…