Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6879485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:51:10+00:00 2026-05-27T04:51:10+00:00

I am coding up an algorithm for constructing a suffix tree in Mathematica based

  • 0

I am coding up an algorithm for constructing a suffix tree in Mathematica based on Ukkonen’s algorithm.

The question I have is, will passing my entire tree structure (which I have stored in a list) to a function to search through, cost my program a lot of memory and time since I have to use some of the functions multiple times in the algorithm?

For example, I have a function that searches for the children of a specific node, and I use the Select function to search the entire tree.

getChildren[parentID_] := Select[tree, #[[3]] == parentID &];

However I need to access the tree, so is it reasonable to pass the entire tree structure to the function? Since it doesn’t seem that there is a way to make a variable global to the entire notebook. Or is there some alternate way to get around this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:51:10+00:00Added an answer on May 27, 2026 at 4:51 am

    No, it does not cost extra memory to pass expressions. As is usual in functional languages, Mathematica objects are immutable: they cannot be modified, instead a new object is created when you transform them using some function. This also means that if you don’t transform them, they’re not copied, no matter how much you pass them around between functions.


    From a user perspective, Mathematica expressions are trees, but I believe that internally they’re stored as directed acyclic graphs, i.e. the same subexpression may be stored only once in memory, regardless of how many times it appears in the full expression (see e.g. the doc page of Share[]).

    Here’s an example to illustrate:

    First, make sure In/Out don’t take up extra memory:

    In[1]:= $HistoryLength = 0;
    

    Check memory usage:

    In[2]:= MemoryInUse[]
    Out[2]= 13421756
    

    Let’s make an expression that takes up a noticeable amount of memory:

    In[3]:= s = f@Range[1000000];
    
    In[4]:= MemoryInUse[]
    Out[4]= 17430260
    

    Now repeat this expression a hundred times …

    In[5]:= t = ConstantArray[s, 100];
    

    … and notice that memory usage barely increases:

    In[6]:= MemoryInUse[]
    Out[6]= 18264676
    

    ByeCount[] is misleading because it doesn’t report the actual physical memory used, but the memory that would be used if common subexpressions weren’t allowed to share the same memory:

    In[7]:= ByteCount[t]
    Out[7]= 400018040
    

    An interesting point to note: if you remove f[...] from s, and make both s and t a plain numerical array, then this memory sharing will not happen, and memory usage will jump to ~400 MB.


    Whether you make tree a global variable or an argument of getChildren, it will not make a difference in memory usage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create an animation to demonstrate LDPC coding which is based
I have to implement the LPC (linear predictive coding) Algorithm with Java and quiet
While I was coding an algorithm of collision detection I have come up at
I've got a question about coding an algorithm for a Texas Instruments TMS320C64xx DSP
I'm coding a suffix array sorting, and this algorithm appends a sentinel character to
I am coding this Sudoku Solver with the following algorithm: Given a grid which
Using this question as the base is there an alogrithm or coding example to
Coding footer naively, if there's not enough content, then there will be empty space
When coding web services, how do you structure your return values? How do you
Im trying to implement my own Huffman Coding algorithm and the priority queue for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.