Zero To DSAZero To DSA
Privacy Policy·Support on Ko‑fi
Constant vs LinearSpace Complexity Analysis

Quadratic vs Linear

easy

Given an array of n integers, you compare every pair of elements. What is the time complexity?

Examples

Input: n = 5
Output: O(n²)
Number of pairs = n*(n-1)/2 ≈ n²/2, which simplifies to O(n²).