416 views
2 votes
2 votes
Let $A$ be an array of $n$ integers, sorted so that $A[1] \leq A[2] \leq \dots \leq A[n]$. You are given a number $x$x. The aim is to find out if there are indices $k$ and $l$ such that $A[k] + A[l] = x$. Design an algorithm for this problem that works in time $O(n)$.

1 Answer

Related questions

2 votes
2 votes
2 answers
1
go_editor asked May 27, 2016
428 views
Let $A$ be array of $n$ integers that is not assumed to be sorted. You are given a number $x$. The aim is to find out if there are indices $k,\: l$ and $m$ such that $A[...
1 votes
1 votes
2 answers
2
3 votes
3 votes
2 answers
4
go_editor asked May 27, 2016
617 views
Consider the code below, defining the function $A$:A(m, n, p) { if (p == 0) return m+n; else if (n == 0 && p == 1) return 0; else if (n == 0 && p == 2) return 1; else if ...