ProgrammingHard

A loop does for (int i = 1; i <= n; i++) { x = i / 2; } with n = 10^9. What is the main cost concern?

  1. A. A quadratic blow-up of memory
  2. B. The loop is undefined because of the division
  3. C. The loop never ends because i / 2 is less than i
  4. D. About 10^9 iterations, which is borderline in one second and may need a closed form

Correct answer: D. About 10^9 iterations, which is borderline in one second and may need a closed form

A simple loop of 10^9 steps takes about a second, so the cost is borderline. Nothing here is undefined or infinite.

More C Programming questions

Exams that ask this topic