>>For those who know about asymptotic behavior:
>>
>>
Given an array of increasing numbers and a number X, create a linear algorithm that finds whether the array contains two numbers that sum to X (and those two numbers if they exist).>>
>>Daniel
>
>This should work (I think)
>
>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 i
It should work, but it may be slow executing. The array is stated to be sorted, so you are supposed to take advantage of that fact - and that is what I see as the tricky part.
Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)