Re: [algogeeks] Re: missing integers in an unsorted array

2010-02-04 Thread srinivas chintagunta
I think this works if elements are sorted . Is it correct? On Mon, Feb 1, 2010 at 5:07 PM, sachin sachin_mi...@yahoo.co.in wrote: A way to solve this problem would be using xor(exclusive OR) xor all the elements from 1 to n.Call it A xor all the elements of the array into a variable B Now

Re: [algogeeks] Re: missing integers in an unsorted array

2010-02-04 Thread Terence
No. This works for all cases. Xor is commutative. On 2010-2-5 13:37, srinivas chintagunta wrote: I think this works if elements are sorted . Is it correct? On Mon, Feb 1, 2010 at 5:07 PM, sachin sachin_mi...@yahoo.co.in mailto:sachin_mi...@yahoo.co.in wrote: A way to solve this problem

Re: [algogeeks] Re: missing integers in an unsorted array

2010-02-04 Thread atul verma
Yup Terence is right. On Fri, Feb 5, 2010 at 11:42 AM, Terence technic@gmail.com wrote: No. This works for all cases. Xor is commutative. On 2010-2-5 13:37, srinivas chintagunta wrote: I think this works if elements are sorted . Is it correct? On Mon, Feb 1, 2010 at 5:07 PM, sachin

[algogeeks] Re: missing integers in an unsorted array

2010-02-01 Thread sachin
A way to solve this problem would be using xor(exclusive OR) xor all the elements from 1 to n.Call it A xor all the elements of the array into a variable B Now missing element = A xor B It works this way xor-ing an element with itself gives 0(p xor p=0) xor-ing an element with 0 gives the element