Data Structures & AlgorithmsVery hardGATE CS · ICPC regional · Product Company SDE
Undirected graph edges: D–C, B–C, A–C, A–B, A–D, 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
- Keys 64, 54, 44 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- A binary tree has preorder traversal [23, 2, 94, 67, 57, 46, 81] and inorder traversal [2, 23, 46, 57, 67, 81, 94]. Reconstructing the…
- Build a binary min-heap in place from the array [29, 45, 8, 5, 74, 90, 69, 56, 38] using bottom-up heapify (sift-down from the last…
- Keys 45, 92, 18, 65, 91, 86, 78, 95 are inserted in this order into an empty BST (no rebalancing). What is the height of the tree (edges…
- Keys 55, 50, 19, 76, 39, 98, 34, 63, 58, 69 are inserted via separate chaining (h(k) = k mod 8, new keys appended to the end of the chain)…
- A trie is built from the words {cat, card, den, cats, dog, do, cap}. Using the trie (walk the prefix's characters, then count all words in…