Re: [algogeeks] Re: Repeated values

2012-11-06 Thread Saurabh Kumar
yes, that was an implementation mistake but what I meant to say was- Adding
extra check of indirect xor'ing could have a pitfall too.
Try the case: [0 1 1 1 4 4]
http://ideone.com/3sreLZ


On 4 November 2012 10:13, Vikram Pradhan vpradha...@gmail.com wrote:

  It should have caught in the first loop where i checked that condition if
 the first value (which is 3 in this case) is repeated or not ...but
 unfortunately i  implemented that wrong ...so now i've corrected that
 mistake ..i hope now it'll work fine ..
 http://ideone.com/MQ44Rt

 the whole idea of using xor is that we don't have to modify the array as
 i've seen this same question somewhere else where the condition was that
 the array is a read only array ..otherwise Don's method will work fine .







 Vikram Pradhan | B.Tech| Computer Science  Engineering | NIT Jalandhar
  | 9740186063 |

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Repeated values

2012-11-02 Thread Vikram Pradhan
@Don :yeah sorry i misinterpreted the if condition ..it'll work fine .

I've modified my previous sol. and in this sol we do not need to modify the
array . Time complexity O(n) and constant space.
http://ideone.com/s2kR24





On Fri, Nov 2, 2012 at 1:14 AM, Don dondod...@gmail.com wrote:

 It won't enter an infinite loop in that case. In fact, it would
 immediately return.
 Don

 On Oct 31, 2:39 pm, Vikram Pradhan vpradha...@gmail.com wrote:
  @Don It will be an infinite loop for some cases  ...like try this i=1,
 and
  a[1] = 5 , a[5] = 5
 
  *Solution:*
 
  As the numbers are from 0 to N-1 so we can xor the value with its index
 in
  a loop . if the result is 0 then there is no repetition else there is
 some
  repetition.
 
  *int result = 0;*
  *for(int i=0;iN;i++)*
  *{*
  *result ^= i ^ array[i];*
  *}*
  *
  *
  *if(result==0)*
  *There is no repetition.*
  *else*
  *There is some repetition.*
 
  Time complexity O(N)
  Space Complexity : constant
 
  check this :http://ideone.com/RXyynB
 
   As the indexes are from 0 to N-1 and numbers are also from 0 to N-1 in
  random order. So if there is no repetition then there is exactly two
 copies
  of same number in set of (values and index) and when we xor all the
 indexes
  to all the numbers the result will be zero because xor of same no. is
 zero.
 
  --
  Vikram Pradhan | B.Tech| Computer Science  Engineering | NIT Jalandhar
  |
  9740186063 |

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Vikram Pradhan | B.Tech| Computer Science  Engineering | NIT Jalandhar  |
9740186063 |

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Repeated values

2012-11-01 Thread Saurabh Kumar
@Vikram - your approach fails for [4 1 1 1 1]

On 1 November 2012 00:09, Vikram Pradhan vpradha...@gmail.com wrote:

 @Don It will be an infinite loop for some cases  ...like try this i=1, and
 a[1] = 5 , a[5] = 5

 *Solution:*

 As the numbers are from 0 to N-1 so we can xor the value with its index in
 a loop . if the result is 0 then there is no repetition else there is some
 repetition.

 *int result = 0;*
 *for(int i=0;iN;i++)*
 *{*
 *result ^= i ^ array[i];*
 *}*
 *
 *
 *if(result==0)*
 *There is no repetition.*
 *else*
 *There is some repetition.*

 Time complexity O(N)
 Space Complexity : constant

 check this : http://ideone.com/RXyynB

  As the indexes are from 0 to N-1 and numbers are also from 0 to N-1 in
 random order. So if there is no repetition then there is exactly two copies
 of same number in set of (values and index) and when we xor all the indexes
 to all the numbers the result will be zero because xor of same no. is zero.


 --
 Vikram Pradhan | B.Tech| Computer Science  Engineering | NIT Jalandhar  |
  9740186063 |

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Repeated values

2012-11-01 Thread Don
It won't enter an infinite loop in that case. In fact, it would
immediately return.
Don

On Oct 31, 2:39 pm, Vikram Pradhan vpradha...@gmail.com wrote:
 @Don It will be an infinite loop for some cases  ...like try this i=1, and
 a[1] = 5 , a[5] = 5

 *Solution:*

 As the numbers are from 0 to N-1 so we can xor the value with its index in
 a loop . if the result is 0 then there is no repetition else there is some
 repetition.

 *int result = 0;*
 *for(int i=0;iN;i++)*
 *{*
 *result ^= i ^ array[i];*
 *}*
 *
 *
 *if(result==0)*
 *There is no repetition.*
 *else*
 *There is some repetition.*

 Time complexity O(N)
 Space Complexity : constant

 check this :http://ideone.com/RXyynB

  As the indexes are from 0 to N-1 and numbers are also from 0 to N-1 in
 random order. So if there is no repetition then there is exactly two copies
 of same number in set of (values and index) and when we xor all the indexes
 to all the numbers the result will be zero because xor of same no. is zero.

 --
 Vikram Pradhan | B.Tech| Computer Science  Engineering | NIT Jalandhar  |
 9740186063 |

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Repeated values

2012-10-31 Thread Vineeth
@Don : Shift all the numbers to the corresponding positions in the first
iteration
And in the second loop check whether the number and the position matches or
not.
O(N) space and O(1) time

constraint : the number's range must be from 0 to N-1

Cheers,


On Wed, Oct 31, 2012 at 3:16 AM, Don dondod...@gmail.com wrote:

 In addition, inputs such as {2,2,0} will fail because when you try to
 make zero negative, it doesn't work so well.
 Don

 On Oct 30, 5:36 pm, Don dondod...@gmail.com wrote:
  That solution is using the sign bit as extra storage, which is clever,
  but if you have an array of unsigned integers and N is more than half
  of the largest unsigned integer, it won't work. There is a way to do
  it without using the sign bit as extra storage.
 
  On Oct 30, 5:16 pm, rahul sharma rahul23111...@gmail.com wrote:
 
 
 
 
 
 
 
   i thnik this is the solution...
 http://www.geeksforgeeks.org/archives/9755
 
   On Wed, Oct 31, 2012 at 2:20 AM, Don dondod...@gmail.com wrote:
We can modify the array. The algorithm should work even if we use
unsigned integers and N is the largest unsigned integer.
 
Don
 
On Oct 30, 4:42 pm, rahul sharma rahul23111...@gmail.com wrote:
 Can we modify the array???we can make index we visit as negative
 and then
 if any one already containing -ve..then its repeating
 
 On Wed, Oct 31, 2012 at 1:40 AM, Don dondod...@gmail.com wrote:
  Does your algorithm work if N=4 and the array is {1,1,2,2}.
 
  Don
 
  On Oct 30, 2:32 pm, arumuga abinesh arumugaabin...@gmail.com
 wrote:
   if sum of all elements = n(n-1)/2 , no elements are repeated
   else some numbers are repeated
 
   On Tue, Oct 30, 2012 at 11:57 PM, Don dondod...@gmail.com
 wrote:
Given an array of N integers in the range 0..N-1, determine
 if any
number is repeated in the array.
Solution should execute in O(n) time and use constant space.
Don
 
--
You received this message because you are subscribed to the
 Google
  Groups
Algorithm Geeks group.
To post to this group, send email to
 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
 
  --
  You received this message because you are subscribed to the
 Google
Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.
 
--
You received this message because you are subscribed to the Google
 Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Repeated values

2012-10-31 Thread apsalar
I think this is the answer - 
http://stackoverflow.com/questions/5739024/finding-duplicates-in-on-time-and-o1-space

On Tuesday, October 30, 2012 2:27:29 PM UTC-4, Don wrote:

 Given an array of N integers in the range 0..N-1, determine if any 
 number is repeated in the array. 
 Solution should execute in O(n) time and use constant space. 
 Don 


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/XPyEFSy1Gh0J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Repeated values

2012-10-31 Thread Don
A solution is to sort the array taking advantage of the fact that if
the contents are in fact a permutation of the values 0..n-1, value x
always goes in position A[x]. Therefore you can immediately swap value
x into the correct position. If that position already contains value
x, you have identified a duplicate.

bool hasDuplicate(int *a, int n)
{
  for(int i = 0; i  n; ++i)
  {
while(a[i] != i)
{
   int j = a[i];
   if (a[j] == j) return true;
   a[i] = a[j];
   a[j] = j;
}
  }
  return false;
}

At first it may appear to be O(n^2) but notice that each pass through
the inner loop puts one value in its correct place. Thus the inner
loop executes at most n times. Unlike a similar solution above, if it
finds a duplicate it immediately returns, so in some cases it doesn't
require n iterations.

This solution is also faster than the solution using the sign bit,
based on a benchmark test I ran.

Don


On Oct 30, 2:27 pm, Don dondod...@gmail.com wrote:
 Given an array of N integers in the range 0..N-1, determine if any
 number is repeated in the array.
 Solution should execute in O(n) time and use constant space.
 Don

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Repeated values

2012-10-30 Thread Don
Does your algorithm work if N=4 and the array is {1,1,2,2}.

Don

On Oct 30, 2:32 pm, arumuga abinesh arumugaabin...@gmail.com wrote:
 if sum of all elements = n(n-1)/2 , no elements are repeated
 else some numbers are repeated







 On Tue, Oct 30, 2012 at 11:57 PM, Don dondod...@gmail.com wrote:
  Given an array of N integers in the range 0..N-1, determine if any
  number is repeated in the array.
  Solution should execute in O(n) time and use constant space.
  Don

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Repeated values

2012-10-30 Thread rahul sharma
Can we modify the array???we can make index we visit as negative and then
if any one already containing -ve..then its repeating

On Wed, Oct 31, 2012 at 1:40 AM, Don dondod...@gmail.com wrote:

 Does your algorithm work if N=4 and the array is {1,1,2,2}.

 Don

 On Oct 30, 2:32 pm, arumuga abinesh arumugaabin...@gmail.com wrote:
  if sum of all elements = n(n-1)/2 , no elements are repeated
  else some numbers are repeated
 
 
 
 
 
 
 
  On Tue, Oct 30, 2012 at 11:57 PM, Don dondod...@gmail.com wrote:
   Given an array of N integers in the range 0..N-1, determine if any
   number is repeated in the array.
   Solution should execute in O(n) time and use constant space.
   Don
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Repeated values

2012-10-30 Thread Don
We can modify the array. The algorithm should work even if we use
unsigned integers and N is the largest unsigned integer.

Don

On Oct 30, 4:42 pm, rahul sharma rahul23111...@gmail.com wrote:
 Can we modify the array???we can make index we visit as negative and then
 if any one already containing -ve..then its repeating







 On Wed, Oct 31, 2012 at 1:40 AM, Don dondod...@gmail.com wrote:
  Does your algorithm work if N=4 and the array is {1,1,2,2}.

  Don

  On Oct 30, 2:32 pm, arumuga abinesh arumugaabin...@gmail.com wrote:
   if sum of all elements = n(n-1)/2 , no elements are repeated
   else some numbers are repeated

   On Tue, Oct 30, 2012 at 11:57 PM, Don dondod...@gmail.com wrote:
Given an array of N integers in the range 0..N-1, determine if any
number is repeated in the array.
Solution should execute in O(n) time and use constant space.
Don

--
You received this message because you are subscribed to the Google
  Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Repeated values

2012-10-30 Thread rahul sharma
i thnik this is the solution...
http://www.geeksforgeeks.org/archives/9755

On Wed, Oct 31, 2012 at 2:20 AM, Don dondod...@gmail.com wrote:

 We can modify the array. The algorithm should work even if we use
 unsigned integers and N is the largest unsigned integer.

 Don

 On Oct 30, 4:42 pm, rahul sharma rahul23111...@gmail.com wrote:
  Can we modify the array???we can make index we visit as negative and then
  if any one already containing -ve..then its repeating
 
 
 
 
 
 
 
  On Wed, Oct 31, 2012 at 1:40 AM, Don dondod...@gmail.com wrote:
   Does your algorithm work if N=4 and the array is {1,1,2,2}.
 
   Don
 
   On Oct 30, 2:32 pm, arumuga abinesh arumugaabin...@gmail.com wrote:
if sum of all elements = n(n-1)/2 , no elements are repeated
else some numbers are repeated
 
On Tue, Oct 30, 2012 at 11:57 PM, Don dondod...@gmail.com wrote:
 Given an array of N integers in the range 0..N-1, determine if any
 number is repeated in the array.
 Solution should execute in O(n) time and use constant space.
 Don
 
 --
 You received this message because you are subscribed to the Google
   Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Repeated values

2012-10-30 Thread Don
That solution is using the sign bit as extra storage, which is clever,
but if you have an array of unsigned integers and N is more than have
of the largest unsigned integer, it won't work. There is a way to do
it without using the sign bit as extra storage.
Don

On Oct 30, 5:16 pm, rahul sharma rahul23111...@gmail.com wrote:
 i thnik this is the solution...http://www.geeksforgeeks.org/archives/9755







 On Wed, Oct 31, 2012 at 2:20 AM, Don dondod...@gmail.com wrote:
  We can modify the array. The algorithm should work even if we use
  unsigned integers and N is the largest unsigned integer.

  Don

  On Oct 30, 4:42 pm, rahul sharma rahul23111...@gmail.com wrote:
   Can we modify the array???we can make index we visit as negative and then
   if any one already containing -ve..then its repeating

   On Wed, Oct 31, 2012 at 1:40 AM, Don dondod...@gmail.com wrote:
Does your algorithm work if N=4 and the array is {1,1,2,2}.

Don

On Oct 30, 2:32 pm, arumuga abinesh arumugaabin...@gmail.com wrote:
 if sum of all elements = n(n-1)/2 , no elements are repeated
 else some numbers are repeated

 On Tue, Oct 30, 2012 at 11:57 PM, Don dondod...@gmail.com wrote:
  Given an array of N integers in the range 0..N-1, determine if any
  number is repeated in the array.
  Solution should execute in O(n) time and use constant space.
  Don

  --
  You received this message because you are subscribed to the Google
Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

--
You received this message because you are subscribed to the Google
  Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Repeated values

2012-10-30 Thread Don
That solution is using the sign bit as extra storage, which is clever,
but if you have an array of unsigned integers and N is more than half
of the largest unsigned integer, it won't work. There is a way to do
it without using the sign bit as extra storage.

On Oct 30, 5:16 pm, rahul sharma rahul23111...@gmail.com wrote:
 i thnik this is the solution...http://www.geeksforgeeks.org/archives/9755







 On Wed, Oct 31, 2012 at 2:20 AM, Don dondod...@gmail.com wrote:
  We can modify the array. The algorithm should work even if we use
  unsigned integers and N is the largest unsigned integer.

  Don

  On Oct 30, 4:42 pm, rahul sharma rahul23111...@gmail.com wrote:
   Can we modify the array???we can make index we visit as negative and then
   if any one already containing -ve..then its repeating

   On Wed, Oct 31, 2012 at 1:40 AM, Don dondod...@gmail.com wrote:
Does your algorithm work if N=4 and the array is {1,1,2,2}.

Don

On Oct 30, 2:32 pm, arumuga abinesh arumugaabin...@gmail.com wrote:
 if sum of all elements = n(n-1)/2 , no elements are repeated
 else some numbers are repeated

 On Tue, Oct 30, 2012 at 11:57 PM, Don dondod...@gmail.com wrote:
  Given an array of N integers in the range 0..N-1, determine if any
  number is repeated in the array.
  Solution should execute in O(n) time and use constant space.
  Don

  --
  You received this message because you are subscribed to the Google
Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

--
You received this message because you are subscribed to the Google
  Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Repeated values

2012-10-30 Thread Don
In addition, inputs such as {2,2,0} will fail because when you try to
make zero negative, it doesn't work so well.
Don

On Oct 30, 5:36 pm, Don dondod...@gmail.com wrote:
 That solution is using the sign bit as extra storage, which is clever,
 but if you have an array of unsigned integers and N is more than half
 of the largest unsigned integer, it won't work. There is a way to do
 it without using the sign bit as extra storage.

 On Oct 30, 5:16 pm, rahul sharma rahul23111...@gmail.com wrote:







  i thnik this is the solution...http://www.geeksforgeeks.org/archives/9755

  On Wed, Oct 31, 2012 at 2:20 AM, Don dondod...@gmail.com wrote:
   We can modify the array. The algorithm should work even if we use
   unsigned integers and N is the largest unsigned integer.

   Don

   On Oct 30, 4:42 pm, rahul sharma rahul23111...@gmail.com wrote:
Can we modify the array???we can make index we visit as negative and 
then
if any one already containing -ve..then its repeating

On Wed, Oct 31, 2012 at 1:40 AM, Don dondod...@gmail.com wrote:
 Does your algorithm work if N=4 and the array is {1,1,2,2}.

 Don

 On Oct 30, 2:32 pm, arumuga abinesh arumugaabin...@gmail.com wrote:
  if sum of all elements = n(n-1)/2 , no elements are repeated
  else some numbers are repeated

  On Tue, Oct 30, 2012 at 11:57 PM, Don dondod...@gmail.com wrote:
   Given an array of N integers in the range 0..N-1, determine if any
   number is repeated in the array.
   Solution should execute in O(n) time and use constant space.
   Don

   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

 --
 You received this message because you are subscribed to the Google
   Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.

   --
   You received this message because you are subscribed to the Google Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.