Einar,
> for i = 1 to alen(myarray)
> for j = 1 to alen(myarray)
> if myarray(i)+myarray(j) = X
> return i,j
> endi
> next j
> next
Your algorithm works but it is quadratic, not linear. A linear algorithm would read each array element once and possibly store one or two values in a variable (hint).
Daniel
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only