Data Structures & AlgorithmsVery hardHCLTech · Wipro pattern
Undirected graph edges: E–D, E–C, A–C, D–C, B–A, B–E, B–D. Using a BFS 2-colouring, is this graph bipartite?
- A. Cannot be determined without edge weights
- B. No, it contains an odd-length cycle
- C. Yes, it is bipartite
- D. Yes, but only if the graph is also a tree
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
- Keys 69, 79, 89 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Keys 4, 74, 93, 84, 37, 87, 63 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into a table…
- Keys 79, 74, 70, 89, 2, 6, 8 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into a table…
- Keys 75, 53, 77, 17, 31, 29, 21, 5, 95 are inserted in this order into an empty BST (no rebalancing). What is the height of the tree…
- Directed edges: A→B (4), A→C (5), C→B (-4), B→D (1). Dijkstra's algorithm, which finalises each vertex once when it is removed from the…
- Keys 43, 46, 99, 82, 78, 23, 40, 44, 60, 34 are inserted via separate chaining (h(k) = k mod 5, new keys appended to the end of the chain)…