Remove duplicated in array with best performance
Sorting is $O(n\log n)$, not $O(n)$.

Also these are asymptotic bounds. Even if one algorithm is $O(n)$ and another is $O(n^2)$, it is possible that, for small-ish values of $n$ the second algorithm is faster.

More concretely, $f(n) = 1000 n$ is $O(n)$ and $g(n)=n^2/1000$ is $O(n^2)$, and both bounds are tight. Still, it will take a while for the first function to become smaller than the second one: for $n&lt;1000000$ the second one is smaller.