finding two positive integers in an array I'm facing a problem these days, the question is saying the following:
" Imagine we are having an array of positive integers called (a) and a variable called (k). Among this integers, we are looking for two numbers such that the sum of these two would be the (k). we are in need of designing such algorithm with complexity O(n) that prints out the locations of this two number(if exist)."

for example:
a[6,3,2, 1, 8]  ----- n=5 ----- k=8 ------ numbers: 6,2

in this case what would be the designing of the algorithm?

Thank you all for your efforts, they worth a lot!
Assuming $k$ can be at least considered to be $O\left(n\right)$, but ideally that $k \ll n$, i.e., $k$ is much smaller than $n$, and there is sufficient memory available, here is a relatively simple method. Have a "list" (note I am calling this as a mathematical name, not necessarily as a computer construct, as things like single-linked lists have individual access times of $O\left(k^2\right)$ (so it'll require that $k \ll n$), but I am assuming will use a contiguous array, so each element can be accessed directly, making individual access times be a small constant), call it $L$, of $\left\lfloor \frac{k}{2} \right\rfloor$ ordered arrays of $2$ positive integers which add to $k$, i.e., $\left(1, k - 1\right), \left(2, k - 2\right), \ldots, \left(\left\lfloor \frac{k}{2} \right\rfloor, \left\lfloor \frac{k + 1}{2} \right\rfloor\right)$. For example, for $k = 3$, we have just $\left(1, 2\right)$ while for $k = 3$, we have $\left(1, 3\right), \left(2, 2\right)$. Next, have some sort of structure attached to each value to keep track of which, if any, element of the main array has been found for it, with special attention paid to the case where $k$ is even due to the repeated value of the last element in $L$, i.e., $\left(\frac{k}{2}, \frac{k}{2}\right)$.

Now, go through each element of the main array. If it is $\lt k$, check the appropriate element in $L$ to see whether or not it already has something associated with it. If so, ignore it. Otherwise, assign the value in $L$ to this main array element. If the other element in the array in $L$ already has something assigned to it also, then you are done. Note that this finds the first set of elements which add to $k$, but there may be other ones. Otherwise, if you finish checking the main array with no array in $L$ matching, then there is no such result. In either case, this is altogether an $O\left(n\right)$ algorithm, with a certain fixed amount for the initial set up of $L$, and a fairly small maximum # of steps for checking each element of the main array. Note the constant to use in the $O\left(n\right)$ function depends a fair bit on how large your $k$ can be in relation to $n$. Also, if there is no particular limit on $k$, especially if you can't have any assurance you can fit the list $L$ into memory, then I believe that both TonyK and Penguino are likely correct, i.e., there is no such algorithm.

Note I don't know what language you are using, so I didn't try to write it in program code. Also, it's been over $35$ years since I wrote any psuedocode, so I didn't want to try to do that either. However, I trust my explanation is sufficient enough for you to understand my method.
A naive solution would be to test each element i with each element j until the sum is achieved. That will be an O(n^2) algorithm 

for i = 1 to n-1 do   
  for j = 2 to n do
    if A[i]+A[j]=k then return (i,j) and halt 
return "no solution"


A better solution would be to sort the array first then check for your equality. That will be O(nlogn)

sort A
i=1
j=n
while (i &lt; j) and (A[i]+A[j] &lt; k) do inc(i) 
while (i &lt; j) and (A[i]+A[j] &gt; k) do dec(j)
if (i &lt;&gt; j) return (i,j) and halt else return "no solution" 


I doubt that an O(n) solution exists for unsorted data. If the data is already sorted then the second algorithm, minus the first line, is O(n).