Data Structures & AlgorithmsHardProduct company OA
An undirected graph has edges 1–2, 2–3, 3–1, 3–4, 4–5, 5–6, 6–4, 6–7, 7–8. How many BRIDGES (edges whose removal disconnects the graph) does it have?
- A. 2
- B. 4
- C. 5
- D. 3
Correct answer: D. 3
Edges on a cycle are never bridges: the triangles 1-2-3 and 4-5-6 are safe. 3–4 joins the two triangles, 6–7 and 7–8 lead to a dead-end path – each of these three disconnects something when removed. Counting only 3–4 and 6–7 (forgetting the last edge to a leaf) gives 2.
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 20, 8, 22, 4, 12, 10, 14, 25 are inserted into an empty BST. What is the lowest common ancestor of 10 and 14, and of 4 and 14?
- Keys 50, 30, 70, 20, 40, 60, 80, 35, 45, 65 are inserted into an empty BST. A range query counts keys in [33, 62], pruning subtrees that…
- A robot moves only right or down from the top-left to the bottom-right cell of this 4 × 4 grid ('#' is blocked). How many paths are there?…
- DFS-based topological sort on the DAG with adjacency lists a: [b, c], b: [d], c: [d, e], d: [f], e: [f], f: [] starts at a, visits…
- DFS with white/grey/black colours detects a cycle in the directed graph with adjacency lists 1: [2, 3], 2: [4], 3: [4], 4: [5], 5: [3]…
- Keys 1 to 7 are inserted in increasing order into an empty AVL tree, then 4 is deleted (a node with two children is replaced by its…