Math Fundamentals18 sections · 814 units
Open in Course

Quadratic Example

(Checking all pairs)

To check if an array has duplicate values, you could compare every element with every other element. This requires two nested loops.

Outer loop runs n times. Inner loop runs n times for each outer iteration. Total: n × n = n² comparisons.

This is O(n²). A hash set can solve this in O(n), but the naive approach is quadratic.