       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[],{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[], {i, 100000}]]

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

>Timing [Q[],{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:= a = Range;
b = Range;
c = Range;

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

Out= {0.054508,Null}

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

Out= {0.055219,Null}

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

Out= {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:= a = Array[# &, 100];
b = Array[# &, 1000];
c = Array[# &, 10000];

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

Out= {0.034209,Null}

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

Out= {0.032917,Null}

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

Out= {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?