Click to See Complete Forum and Search --> : A simple algorithm


jig_nayi
December 13th, 2006, 04:28 PM
Pls help me with this algorithm

We have an array of integers which is sorted. We are given a integer m.

Define an algorithm that determines wether there exist two integers X < Y in the array, such that X + y = m

This must run in linear time - O (n)

Thanks

JimK
December 13th, 2006, 06:09 PM
Hello,

I found a very good solution through the internet.
It runs in linear time - Ɵ(n) and it uses a hash table to find these two integers that sum to m....

link (http://blog.kirupa.com/?p=20)