a o(n^2) time in the worst case