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?

  1. A. 2
  2. B. 3
  3. C. 1
  4. 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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic