Our website loads in split second powered by Schema Theme. Thanks to MyThemeShop

Finding duplicates in a sorted array – O(nlogn)

Duplicates in the array can be found by general Brute force solution in the O(n^2) time. Can there be any solution that would take less time than the Brute force solution? Yes. obviously, by sorting the array input. For any problem statement, for improving the time complexity check whether sorting on input will work.If you use Quick sort or Merge sort for sorting the array, it will take O(nlogn) time, and for checking duplicates, it will take O(n) time. On the whole asymptotically, it is , O(nlogn) time.

Finding duplicates in a sorted array – O(nlogn)

 Sample Test client for above program