commits the actual code for the o(n) squared algorithm