Complexity O(N):

void findSum(int sum, int[] vec) {

Set set= new HashSet(vec.length);

for (int i : set) {

int j = sum - i;

if (set.contains(j)) {

printf("%i + %i = %i \n", i, j, sum);

}

set.add(i);

}

Sort the array using quick sort. Start from the highest value on top, say x, and binary search the array to see if there exists n-x. If not, remove top element and shrink array by 1 and repeat. If found, there's your solution.