Re: Complement replacement
- To: mathgroup at smc.vnet.net
- Subject: [mg58628] Re: [mg58608] Complement replacement
- From: yehuda ben-shimol <bsyehuda at gmail.com>
- Date: Sun, 10 Jul 2005 16:51:51 -0400 (EDT)
- References: <200507100912.FAA06500@smc.vnet.net>
- Reply-to: yehuda ben-shimol <bsyehuda at gmail.com>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
I suspect that from the solutions offered below you mean the
procedural oriented paradigm which is given by the last solution.
note, that fisrt it is recommended to Sort[] your table. This is
usually done in O(n Log[2,n]) run time complexity and will improve any
solution that you will choose to use later. I'm also sure that you
will get many other solutions and approaches
For the code offered below, the result is given in variable res, and
the rest is to compare the run time (ignoring sorting that all rely
on).
sp = Sort[pp = Array[Random[Integer, {1, 1000}] &, 1000]];
(res = Table[If[! MemberQ[sp, i], i], {i, 1000}] // Union //
Most) // Timing // First
(res = Reap[Do[If[! MemberQ[sp, i], Sow[i]], {i,
1000}]] // Rest // Flatten) // Timing // First
(res = Reap[Do[If[! MemberQ[sp, i], Sow[i]], {i,
1000}]] // Rest // Flatten) // Timing // First
k = 1; (res = Rest[Reap[(While[k < #, If[++k < #, Sow[k]]]) & /@ sp]] //
First // Flatten) // Timing // First
The running times that I got on my computer for the specific example
genrated by the rundom numbers are:
0.22 Second
0.191 Second
0.18 Second
0.01 Second
yehuda
On 7/10/05, konstantpi at mail15.com <konstantpi at mail15.com> wrote:
> hi
> in the list:
> pp=Table[Random[Integer, {1, 1000}], {i, 1000}];
> how could i know which numbers from 1 to 1000 does not exist in the
> pp List.
> but without using:
> Complement[Table[i,{i,1000}],pp]
> regards
>
>
- References:
- Complement replacement
- From: konstantpi@mail15.com
- Complement replacement