Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'memory problem for recursive algorithm' topicStudent Support Forum > General > Archives > "memory problem for recursive algorithm"

Next Comment >Help | Reply To Topic
Author Comment/Response
02/21/08 7:37pm


I am using Mathematica for a recursive algorithm to compute a variable, say, x_i. The algorithm only needs the previous N x's to compute the next x_i. Now I tried to get an x_m, where m is quite large.

I wrote two different Mathematica programs for this problem. In the first one, I saved all the x_i, i=1,...,m, in a 1 x m table. In the second, I only keep the most recent N x_i. So the table size is 1 x N, which is much smaller. To do this, for each i>N, I use "Drop" to get rid of the first element, and "Append" to add a new element. (I also tried to move the 2 to N element to 1 to N-1, and add a new one at the end.)
The second way is supposed to require less memory and faster.

What surprised me is that the second way takes much long time, and the memory runs out very fast, and the first way works just well.

I guess there is something very inefficient in what I did. Could anyone help me out? Thanks!


URL: ,

Subject (listing for 'memory problem for recursive algorithm')
Author Date Posted
memory problem for recursive algorithm Xiaolu 02/21/08 7:37pm
Re: memory problem for recursive algorithm yehuda ben-s... 02/27/08 4:05pm
Re: memory problem for recursive algorithm Peter Pein 03/06/08 10:03pm
Next Comment >Help | Reply To Topic