[algogeeks] Re: 答复: [algogeeks] Re: Array of int egers

2007-11-25 Thread MJ
Hi I got the answer. Correcting the program as we need to add a condition to take care of -ve values Please correct me if I am wrong int i = 0; int nPair while (in) { nPair = X - array[i]; if(nPair = 0) continue; else if(bitmap[nPair] == marked) printf(found the

[algogeeks] Re: 答复: [algogeeks] Re: Array of int egers

2007-11-23 Thread MJ
Hi James, your approach is cool, The bitmap approach works in O(n), but as mention by dave, it take extra memory and initialization. If we dont want to use extra memory, can it be done in O(n)? Thank You MJ On Nov 21, 8:11 pm, Dave [EMAIL PROTECTED] wrote: Okay. This works better. It is

[algogeeks] Re: 答复: [algogeeks] Re: Array of int egers

2007-11-23 Thread MJ
Hi James, As per your solution the variable pair can go negative and if Array[i] X, and in that case you can not use bitmap[pair] which will give an exception as we can not access the array elements using -ve value. SO how will you take care of -ve values of variable pair... pair = X -

[algogeeks] Re: 答复: [algogeeks] Re: Array of int egers

2007-11-21 Thread Dave
Okay. This works better. It is O(n), but also requires a large amount of extra memory ( regard 512MB to be large), with a corresponding huge constant overhead to initialize the bitmap. Can you estimate, using reasonable assumptions, the n for which the O(n log n) algorithm using sorting would be