ProgrammingHard

A program finds the number of pairs (i, j) with i < j among n = 10^5 elements by a nested loop. How many pair checks happen?

  1. A. About 5 x 10^9
  2. B. About 10^5
  3. C. About 10^10
  4. D. About 2 x 10^5

Correct answer: A. About 5 x 10^9

There are n(n-1)/2 pairs, which is 4999950000, about 5 x 10^9. That is too many for a one-second limit.

More C Programming questions

Exams that ask this topic