FW: Re: Lists to mask other lists

*To*: mathgroup at smc.vnet.net*Subject*: [mg19295] FW: [mg19275] Re: Lists to mask other lists*From*: "Ersek, Ted R" <ErsekTR at navair.navy.mil>*Date*: Thu, 12 Aug 1999 22:34:49 -0400*Sender*: owner-wri-mathgroup at wolfram.com

In [mg19275] Allan Hayes noted that my response to the subject "Lists to mask other lists" is very slow in timing tests. -------------------------- Consider the list below. In[1]:= lst1 = lst2 = {91,92,93,94,95,96}; ---------------- In essence the timing champ (by Allan Hayes) uses the line below. In[2]:= lst1[[{2,3,5}]]=a;lst1 Out[2]= {91,a,a,94,a,96} ----------------- My solution which is dreadfully slow is essentially the next line. In[3]:= ReplacePart[lst2,a,{{2},{3},{5}}] Out[3]= {91,a,a,94,a,96} ----------------- The timing test below shows that ReplacePart (as used above) is a little worse than O[n^2]. So we know ReplacePart isn't the smart solution for this type of situation. Well ReplacePart has several other forms. I wonder if they are also sluggish. In[4]:=test[n_]:= (size=2Floor[1000*2^n]; p1=Union[Table[{Random[Integer,{1,size}]}, {size/2}]]; lst2=Table[Random[],{size}]; t1=(ReplacePart[lst2,a,p1];//Timing//First); {size,t1} ) In[5]:= data=Table[test[n],{n,0,4}] Out[5]= {{2000, 0.33 Second}, {4000, 1.37 Second}, {8000, 5.82 Second}, {16000, 27.19 Second}, {32000, 130.39 Second}} ------------- Regards, Ted Ersek