Re: searching for missing element in an array
- From: Logan Shaw <lshaw-usenet@xxxxxxxxxxxxx>
- Date: Sat, 31 May 2008 02:00:06 -0500
Juha Nieminen wrote:
Ico wrote:Juha Nieminen <nospam@xxxxxxxxxxxxxx> wrote:Ico wrote:See rossum's reply, he explains the algorithm there.For example, can you tell in advance what the sum of allI fail to understand how that is relevant to the problem in question.
numbers [1..n] is, without actually adding them all up ?
Yes, being able to calculate the sum of integers 1-n without doing an
explicit loop is faster, but it doesn't change the O(n) complexity of
the requested algorithm.
That didn't answer my question. His algorithm is still O(n) regardless
of whether you calculate the sum of integers between 1 and n with a
mathematical formula or in a loop.
The algorithm that involves summing doesn't purport to be more efficient
than O(n). Asking whether there is an easy way to find sum(1..n) without
adding them all up does not imply that this ability solves the problem
in an especially quick manner. It is just a question meant to spur
thought about a way to solve the problem which is really simple and
easy to implement.
- Logan
.
- References:
- searching for missing element in an array
- From: srk
- Re: searching for missing element in an array
- From: Ico
- Re: searching for missing element in an array
- From: SRK
- Re: searching for missing element in an array
- From: Ico
- Re: searching for missing element in an array
- From: Juha Nieminen
- Re: searching for missing element in an array
- From: Ico
- Re: searching for missing element in an array
- From: Juha Nieminen
- searching for missing element in an array
- Prev by Date: Re: searching for missing element in an array
- Next by Date: Re: searching for missing element in an array
- 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
|