Corrected some corner cases
Implemented an O(n) algorithm
Added randomisation to the O(n) algorithm