Data Structures & AlgorithmsHardProduct Company SDE · greedy theory

Problem: Which property does the 'exchange argument' prove for an optimal greedy algorithm?

  1. A. Any optimal solution can be transformed to agree with the greedy choice without getting worse
  2. B. The greedy choice is always the largest value
  3. C. The algorithm is randomised
  4. D. The output is always unique

Correct answer: A. Any optimal solution can be transformed to agree with the greedy choice without getting worse

The exchange argument swaps an optimal solution's element for the greedy one and checks that the value does not decrease.

More Coding Interview Problems questions

Exams that ask this topic