# What's a non-trivial Mathematica program involving conscious choice of stack vs. queue data structure?

In a typical computer science algorithms course, much attention is given to the discussion of queues vs. stacks as a data structure programmers need to consciously choose from to achieve algorithmic performance. What's a good Mathematica program example that also involves (explicitly) choosing data structures? Most of these "implementation details" or algorithmic design tactics is automated in a black box fashion by Mathematica's Automatic idiosyncrasy.

-
M is a high level language (4th generation if you will), so most of the time, you do not need to implement these data structures since they are not needed, Mathematica commands already there to do pretty much anything you want. But if you want to implement them you can. Here is a link that shows how to library.wolfram.com/conferences/devconf99/lichtblau –  Nasser Jul 1 '14 at 0:11
I also do not think Mathematica is the right choice for computer science algorithms course, since it is a high level language. Same as Matlab is not a good choice, and neither is Maple. We used Pascal for this at school where one can 'see' things. In higher level languages, the need to implement such data structures is not needed as much as in low level and system programming. –  Nasser Jul 1 '14 at 0:33
Search for "Data Structures" here mathematica.stackexchange.com/q/18/193 –  belisarius Jul 1 '14 at 1:12
The example of a trie used to implement prefix word search here, and particularly its application to the Boggle problem are I think good examples where the right choice of data structures was crucial. The first one also uses a stack to collect letters for words, while the last one also uses linked lists to store partial results. –  Leonid Shifrin Jul 1 '14 at 9:08
A stack is a good mechanism for doing a depth-first traversal. Also it is useful for branch-and-bound integer programming e.g. as indicated here or here. A queue might be useful for a breadth-first traversal. A priority queue (which is not the same as a queue) can be used for sorting, or for branch-and-prune types of programming. –  Daniel Lichtblau Jul 1 '14 at 16:47