in Lisp-like systems, cons is the normal way to PREPEND an element to a list. Functions that append to a list are much more expensive because they walk the list to the end and then replace the final null with a reference to the appended item. IOW (pseudoLisp)
(prepend list item) = (cons item list) = cheap!
(append list item) = (cond ((null? list) (cons item null))
(#t (cons (car list (append (cdr list) item)))))
Question is whether the situation is similar in Mathemtica? In most regards, Mathematica’s lists seem to be singly-linked like lisp’s lists, and, if so, we may presume that Append[list,item] is much more expensive than Prepend[list,item]. However, I wasn’t able to find anything in the Mathematica documentation to address this question. If Mathematica’s lists are doubly-linked or implemented more cleverly, say, in a heap or just maintaining a pointer-to-last, then insertion may have a completely different performance profile.
Any advice or experience would be appreciated.
Mathematica’s lists are not singly linked lists like in Common Lisp. It is better to think of mathematica lists as array or vector like structures. The speed of insertion is O(n), but the speed of retrieval is constant.
Check out this page of Data structures and Efficient Algorithms in Mathematica which covers mathematica lists in further detail.
Additionally please check out this Stack Overflow question on linked lists and their performance in mathematica.