What is the time complexity of two nested loops, each executing N times?

Options

  • A. O(N)
  • B. O(log N)
  • C. O(N2)
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. O(N2)

Detailed Explanation

Two nested loops that each execute N times generally perform N × N operations, giving a time complexity of O(N2), called quadratic time. For example, comparing every pair of elements in an array commonly requires nested loops and can result in O(N2) complexity. Nested loops do not automatically mean O(N2); the exact complexity depends on how many times each loop actually executes.