question: static boolean pairSum ( int ar [ ] , int x ) { Arrays . sort ( ar ) ; int len = ar . length ; for ( int i = 0 , j = len - 1 ; i < j ; ) { if ( ar [ i ] + ar [ j ] == x ) { return true ; } else if ( ar [ i ] + ar [ j ] < x ) { i ++ ; } else { j -- ; } } return false ; }
target:  Using sorting. If we use Merge Sort or Heap Sort then (-)(nlogn) in worst case. If we use Quick Sort then O(n^2) in worst case.