Quadratic Complexity - O(n^2)

If an algorithm’s time complexity is quadratic, it means that the runtime of the algorithm is directly proportional to the square of the size of the input. (Reading time: under 1 minute)

A common example of an algorithm with quadratic time complexity is by looping over an array, and comparing the current element with all other elements in the array. We have to loop over n elements, and for every element, we again have to loop over n elements. This ends up being n * n, which is n^2.

Get hands-on with 1400+ tech skills courses.