Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: Algorithm Analysis Course: Should I use Mathematica for projects?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg127296] Re: Algorithm Analysis Course: Should I use Mathematica for projects?
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sat, 14 Jul 2012 01:32:09 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

On 7/13/12 at 2:55 AM, fateman at cs.berkeley.edu (Richard Fateman)
wrote:

>An example.

>Create 3 arrays.

>A=Table[i,{i,0,100}];
>B=Table[i,{i,0,1000}];
>Q=Table[i,{i,0,10000}];

>Try updating the 50th element of each of these items, which look
>like arrays in Mathematica.

>Timing [A[[50]],{i,0,100000}]

It is hard to understand what you mean here. If I paste what you
posted into Mathematica I see the portion {i,0,100000} colored
red. Not surprising since Timing accepts one argument not two.
Perhaps you meant something like

Timing[Do[a[[50]], {i, 100000}]]

>Timing [B[[50]],{i,0,100000}]

>Timing [Q[[50]],{i,0,100000}]

>On my computer, these results take 0.266 seconds, 0.453 seconds, and
>2.25 seconds,

Assuming you did mean repeatedly reading the 50th element of
each list, I cannot reproduce your results. I get

In[1]:= a = Range[100];
b = Range[1000];
c = Range[10000];

In[4]:= Timing[Do[a[[50]], {i, 100000}]]

Out[4]= {0.054508,Null}

In[5]:= Timing[Do[b[[50]], {i, 100000}]]

Out[5]= {0.055219,Null}

In[6]:= Timing[Do[c[[50]], {i, 100000}]]

Out[6]= {0.053313,Null}

which indicates a constant access time.

>Now, instead of creating these guys as what appears to be arrays,
>one uses

>A=Array[#&,100]
>B=Array[#&,1000]
>Q=Array[#&,10000]

>How does that change the results?

On my machine, not much

In[8]:= a = Array[# &, 100];
b = Array[# &, 1000];
c = Array[# &, 10000];

In[11]:= Timing[Do[a[50], {i, 100000}]]

Out[11]= {0.034209,Null}

In[12]:= Timing[Do[b[50], {i, 100000}]]

Out[12]= {0.032917,Null}

In[13]:= Timing[Do[c[50], {i, 100000}]]

Out[13]= {0.033273,Null}




  • Prev by Date: Re: Algorithm Analysis Course: Should I use Mathematica for projects?
  • Next by Date: Re: Quit and Restart kernel quickly?
  • Previous by thread: Re: Algorithm Analysis Course: Should I use Mathematica for projects?
  • Next by thread: Re: Algorithm Analysis Course: Should I use Mathematica for projects?