William
asked

Expert
Kelish Rai answered
That's right. Quadratic time complexity (O(n²)) is commonly associated with nested loops, where the number of operations grows in proportion to the square of the input size.
For example, consider this Python code:
# This function runs n * n times
def print_pairs(arr):
for i in range(len(arr)):
for j in range(len(arr)):
print(i, j)
lst = [1, 2, 3, 4, 5]
print_pairs()Here, for every element in the list, another loop runs through all elements again, leading to O(n²) complexity.
Python
This question was asked as part of the Complexity Calculation course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer