title: what is the time complexity of the three sum algorithm
body: <p>it is a function to find three numbers in array whoose sum is equal to zero.</p>
  
  <pre><code>//helper function
  bool isPresent(int*arr, int size, int index, int num)
  {
      for (int i = index; i &lt; size; i++)
      {
          if (arr[i] == num)
              return true;
      }
      return false;
  }
  bool threesum(int*arr,int size)
  {
      int i = 0, j = 1;
      int sum = arr[i] + arr[j];
      while (i &lt; size-2)
      {
          if (isPresent(arr, size, j + 1, -sum) == true)
          {
              cout &lt;&lt; arr[i] &lt;&lt; " + " &lt;&lt; arr[j] &lt;&lt; " + " &lt;&lt; -sum &lt;&lt; '\n';
              return true;
          }
          if (j == size)
          {
              i++;
              j = i + 1;
          }
          j++;
          sum = arr[i] + arr[j];
      }
      return false;
  }
  </code></pre>
  
  <p>there are two loops in the threeSum function one is while up to size of array
  second one is isPresent whose time complexity is O(n) so the time complexity of threesum function should be O(n^2) but while loop iterates more time because of j, So is  the time complexity of threesum function is O(n^2) or O(n^3)?</p>