title: Find a pair of elements from an array whose sum equals a given number
body: <p>Given array of n integers and given a number X, find all the unique pairs of elements (a,b), whose summation is equal to X.</p>
  
  <p>The following is my solution, it is O(nLog(n)+n), but I am not sure whether or not it is optimal.</p>
  
  
  
  <pre class="lang-cpp prettyprint-override"><code>int main(void)
  {
      int arr [10] = {1,2,3,4,5,6,7,8,9,0};
      findpair(arr, 10, 7);
  }
  void findpair(int arr[], int len, int sum)
  {
      std::sort(arr, arr+len);
      int i = 0;
      int j = len -1;
      while( i &lt; j){
          while((arr[i] + arr[j]) &lt;= sum &amp;&amp; i &lt; j)
          {
              if((arr[i] + arr[j]) == sum)
                  cout &lt;&lt; "(" &lt;&lt; arr[i] &lt;&lt; "," &lt;&lt; arr[j] &lt;&lt; ")" &lt;&lt; endl;
              i++;
          }
          j--;
          while((arr[i] + arr[j]) &gt;= sum &amp;&amp; i &lt; j)
          {
              if((arr[i] + arr[j]) == sum)
                  cout &lt;&lt; "(" &lt;&lt; arr[i] &lt;&lt; "," &lt;&lt; arr[j] &lt;&lt; ")" &lt;&lt; endl;
              j--;
          }
      }
  }
  </code></pre>