\begin{algorithm} \caption{Two Sum} \begin{algorithmic} \INPUT An array $S[1..n]$ representing a set of $n$ integers and an integer $x$ . \OUTPUT Whether there is two elements in $S$ whose summation equals $x$ . \STATE \CALL{MergeSort}{$S, 1, n$} \COMMENT{$\Theta(n\log n)$} \STATE $i = 1$ \STATE $j = n$ \WHILE{$i < j$} \IF{$S[i] + S[j] < x$} \STATE $i = i + 1$ \ELSEIF{$S[i] + S[j] > x$} \STATE $j = j - 1$ \ELSE \RETURN \TRUE \ENDIF \ENDWHILE \RETURN \FALSE \end{algorithmic} \end{algorithm}