Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2
Undirected graph on vertices A, B, C, D, E, F with edges, in this exact order: B–D (1), A–D (1), B–F (1), C–D (1), D–F (1), B–E (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
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(7) and count every invocation of f…
- Array [27, 5, 12, 25, 10, 1, 22, 2] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the…
- Keys [39, 30, 10, 5, 31, 38, 32, 20, 1] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…
- Distinct words ['a', 'b', 'ba', 'bb', 'aaa', 'ac'] are inserted into an empty trie (one node per character, shared prefixes share nodes…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–E (1), A–G (1), B–C (1), B–E (1), B–F (1), C–F (1), C–G (1), D–E (1), D–G…
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(11) and count every invocation of f…