Re: searching for missing element in an array
- From: Ben Pfaff <blp@xxxxxxxxxxxxxxx>
- Date: Thu, 03 Jul 2008 22:15:59 -0700
pete <pfiland@xxxxxxxxxxxxxx> writes:
srk wrote:
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.
There are other ways to do it but,
your question is an xor checksum exercise.
I think that it takes a programmer to regard this as a question
most naturally answered with xor. Anyone else would use
subtraction: sum the numbers in the array and subtract from
n*(n+1)/2.
--
Ben Pfaff
http://benpfaff.org
.
- Follow-Ups:
- References:
- Prev by Date: Next Generation Test Management System
- Next by Date: Re: Suffix trees versus prefix arrays
- 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
|