427 views
2 votes
2 votes
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[k] + A[l] + A[m] = x$. Design an algorithm for this problem that works in time $O(n^2)$.

2 Answers

Related questions

2 votes
2 votes
1 answer
1
go_editor asked May 27, 2016
416 views
Let $A$ be an array of $n$ integers, sorted so that $A \leq A \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...
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 ...