What is the time complexity of a loop inside a loop, each running n times?

  • AO(n)
  • BO(log n)
  • CO(n²)
  • DO(n log n)
Show answerHide answer

Correct answer C

A loop inside another loop is called a nested loop. If both loops run n times, the inner loop runs n times for each iteration of the outer loop. Total iterations = n × n = n². Therefore, the time complexity is O(n²).