Re: searching for missing element in an array
- From: "Bartc" <bc@xxxxxxxxxx>
- Date: Fri, 30 May 2008 21:35:13 GMT
"Richard Heathfield" <rjh@xxxxxxxxxxxxxxx> wrote in message
news:WJSdnRXXlf9Xxd3VnZ2dneKdnZydnZ2d@xxxxxxxxx
user923005 said:
...."Suppose we have n numbers(from 1 to n) and there is an array of size
n-1. How can we find, which number is missing from the array if
numbers 1 to n are being placed in array randomly."
"The trick" is therefore guaranteed to work provided only that n(n-1)/2
does not exceed the maximum possible value for a number on the host
system.
I completely disagree.
An array initialized with -1 or with INT_MAX would also fit the
initial description.
I agree that the array could be initialised with -1 or INT_MAX or any
other
number you care to mention, but this makes no difference because all those
values are known to be overwritten by values in the range 1 to n, for the
reason I stated above.
An array of all 1's could also fit the description. Each 1 is in the range 1
to n.
--
Bartc
.
- Follow-Ups:
- Re: searching for missing element in an array
- From: Richard Heathfield
- Re: searching for missing element in an array
- References:
- searching for missing element in an array
- From: srk
- Re: searching for missing element in an array
- From: rossum
- Re: searching for missing element in an array
- From: user923005
- Re: searching for missing element in an array
- From: CBFalconer
- Re: searching for missing element in an array
- From: user923005
- Re: searching for missing element in an array
- From: Richard Heathfield
- Re: searching for missing element in an array
- From: user923005
- Re: searching for missing element in an array
- From: Richard Heathfield
- searching for missing element in an array
- Prev by Date: Re: searching for missing element in an array
- Next by Date: Re: line by line compiling in c
- Previous by thread: Re: searching for missing element in an array
- Next by thread: Re: searching for missing element in an array
- Index(es):
Relevant Pages
|