Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2
Undirected graph on vertices A, B, C, D, E, F with edges, in this exact order: A–B (1), A–D (1), A–F (1), B–E (1), A–E (1), A–C (1). Weights are ignored. Process the edges in the listed order and add an edge to the matching whenever neither endpoint is already matched. How many edges does this greedy matching contain?
- A. 2
- B. 3
- C. 1
- D. 6
Correct answer: C. 1
The greedy scan adds 1 edges, but a better arrangement pairs more vertices (2 is the maximum). Taking edges in input order is maximal, not maximum.
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
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–G (1), A–H (1), B–C (1), C–D (1), C–E (1), C–G (1), F–G (1)…
- Array A = [1, 16, 18, 4, 25, 5, 13, 21]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 23? (A trie with subtree counts answers this…
- 5 × 5 grid, rows top to bottom ('#' = blocked, '.' = open): ..... / ..#.. / ..... / ..#.. / #..... Count the paths from top-left to…
- Undirected graph on vertices A, B, C, D, E, F, G with weighted edges A–C (5), A–E (5), A–F (4), B–D (6), B–E (1), B–F (6), B–G (8), C–G…
- Rooted tree with root 0 and vertices 0 to 8; the edges are 0–1, 0–2, 2–3, 2–4, 4–5, 1–6, 1–7, 3–8 (parent–child). Every edge has length 1…
- Keys are inserted in the order 40 89 17 61 57 into an empty binary search tree. Then the key 40 (which has two children) is deleted by…