Implemented O(n^2) and O(nlogn) algorithms