MathGroup Archive 2004

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

Search the Archive

Re: faster sublist checking

  • To: mathgroup at
  • Subject: [mg48719] Re: faster sublist checking
  • From: koopman at (Ray Koopman)
  • Date: Fri, 11 Jun 2004 03:52:54 -0400 (EDT)
  • References: <ca6hlt$fgj$>
  • Sender: owner-wri-mathgroup at

gimbo20032003 at (giorgio borghi) wrote in message 
news:<ca6hlt$fgj$1 at>...
> which is the faster implementantion of function that checks if a list
> A is a sublist of B. es:  A={3,4,5} B={1,2,3,4,5,6,7} gives True?

In[1]:= B = Table[Random[Integer],{1*^4}];

In[2]:= A = Table[Random[Integer],{10}]
Out[2]= {1,0,0,1,1,0,1,0,0,0}

This is equivalent to Jens-Peer's probably-shortest solution:

In[3]:= MatchQ[B,{__,Sequence@@A,__}] //Timing
Out[3]= {17.2419 Second,True}

This is almost as short, and much faster:

In[4]:= MemberQ[Partition[B,Length[A],1],A] //Timing
Out[4]= {0.999832 Second,True}

  • Prev by Date: RE: Creating combinations from a group of sets
  • Next by Date: Re: Combining plots
  • Previous by thread: Re: faster sublist checking
  • Next by thread: Re: faster sublist checking