Seems kind of simple to be a named problem... Is there a reason you think it has a formal name?
The 'literature' algorithm you cited is very simple. What is the source? Do they quote a name?
Best Regards,
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
This problem is called, "given two sorted arrays A and B and an integer k, find the element in A and the element in B that sum to k".
Only interesting problems get names. This one is not interesting.
Also, the solution you gave is not the most efficient. If len(A) >= len(B), It is O(len(A)). If you do a binary search across A and B, you can reach the solution in O(log(len(A))) time.
Not sure I see the time complexity you state. Assume without loss of generality that len(A) >= len(B), then the algorithm is:
Code:
foreach b in B
if k-b in A
return a, b
endfor
otherwise return false
Where if k-b in A can be done in O(log(A)) time by binary search. This gives a runtime complexity of O(B log(A)).
By contrast, the algorithm given by AEmme has complexity O(A+B) ~ O(A), which is likely less.
Agree? Or did I miss something?
Best Regards,
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Bookmarks