Data Structures & AlgorithmsVery hard

Why is the inequality test for a non-degenerate triangle with sorted sides written as a_i + a_j > a_k for the largest side a_k?

  1. A. The two shorter sides must together exceed the longest side; if this holds, the other two inequalities follow automatically.
  2. B. All three pairs of sides must sum to more than the third.
  3. C. The longest side must equal the sum of the other two.
  4. D. Only the shortest side matters.

Correct answer: A. The two shorter sides must together exceed the longest side; if this holds, the other two inequalities follow automatically.

With sides sorted, a_i + a_k > a_j and a_j + a_k > a_i hold automatically once a_i + a_j > a_k, so one comparison suffices. Equality would give a degenerate triangle with zero area.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic