Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Complement replacement

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58620] Re: Re: [mg58608] Complement replacement
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 10 Jul 2005 16:51:38 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

This looks at the effect of removing the redundancy from pp before using the 
complement mechanism 

pp=Table[Random[Integer,{1,1000}],{1000}];

r=Range[1000];

Timing[Length[c1=
      Complement[r,pp]]]

{0.000913 Second,387}

Timing[Length[c2=
      Select[r,!MemberQ[pp,#]&]]]

{0.395094 Second,387}

Timing[Length[c3=
      Cases[r,_?(!MemberQ[pp,#]&)]]]

{0.400645 Second,387}

Timing[Length[c4=
      DeleteCases[r,_?(MemberQ[pp,#]&)]]]

{0.435794 Second,387}

With Complement, removing the redundancy in pp first is detrimental to the 
overall timing

Timing[p=Union[pp];Length[c5=
      Complement[r,pp]]]

{0.00131 Second,387}

However, the alternatives show a net improvement

Timing[p=Union[pp];Length[c6=
      Select[r,!MemberQ[p,#]&]]]

{0.261277 Second,387}

Timing[p=Union[pp];Length[c7=
      Cases[r,_?(!MemberQ[p,#]&)]]]

{0.267076 Second,387}

Timing[p=Union[pp];Length[c8=
      DeleteCases[r,_?(MemberQ[p,#]&)]]]

{0.261073 Second,387}

c1==c2==c3==c4==c5==c6==c7==c8

True


Bob Hanlon

> 
> From: Bob Hanlon <hanlonr at cox.net>
To: mathgroup at smc.vnet.net
> Date: 2005/07/10 Sun AM 07:48:12 EDT
> Subject: [mg58620] Re: [mg58608] Complement replacement
> 
> pp=Table[Random[Integer,{1,1000}],{1000}];
> 
> r=Range[1000];
> 
> Timing[Length[c1=
>       Complement[r,pp]]]
> 
> {0.000934 Second,368}
> 
> Timing[Length[c2=
>       Select[r,!MemberQ[pp,#]&]]]
> 
> {0.39567 Second,368}
> 
> Timing[Length[c3=
>       Cases[r,_?(!MemberQ[pp,#]&)]]]
> 
> {0.401009 Second,368}
> 
> Timing[Length[c4=
>       DeleteCases[r,_?(MemberQ[pp,#]&)]]]
> 
> {0.401319 Second,368}
> 
> c1==c2==c3==c4
> 
> True
> 
> 
> Bob Hanlon
> 
> > 
> > From: konstantpi at mail15.com
To: mathgroup at smc.vnet.net
> > Date: 2005/07/10 Sun AM 05:12:22 EDT
> > Subject: [mg58620] [mg58608] Complement replacement
> > 
> > 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
> > 
> > 
> 

Bob Hanlon
Chantilly, VA


  • Prev by Date: Re: Mathematica: how to set the format of binary numbers in plotting?
  • Next by Date: Re: Complement replacement
  • Previous by thread: Re: Complement replacement
  • Next by thread: Re: Complement replacement