Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

need help for Hash Function in Java

Hello,

I have question about hash function in java.
I have a problem to solve in java .

The problem is you have array of integers say a[3] -- has 2 3 4 5
now i have integer b = 7.

We have to write a programm that if sum of any 2 numbers in array equals to b then return true else return false.

Problem is very easy i did this using 2 for loops but the thing is that using 2 for loops you are getting O(n^2) so this is not good.

I need to used some method to make it 0(N) which is linear.So i thought we can use hash functionas it is O(N) donot worry about memory as hash takes alot of memory.

So i need someone can solve this problem in hash table using java.I new to java and have no idea about hash table.

So kindly send me the code for this or explain me how to use hash thing.
my email is alirazvi@gmail.com

Ali
[899 byte] By [alirazvi] at [2007-11-11 6:39:20]