A spaghetti stack is an N-ary tree data structure in which child nodes have pointers to the parent nodes (but not vice-versa)
Spaghetti stack structure is used in situations when records are dynamically pushed and popped onto a stack as execution progresses, but references to the popped records remain in use. Following are some applications of Spaghetti Stack.
Compilers for languages such as C create a spaghetti stack as it opens and closes symbol tables representing block scopes. When a new block scope is opened, a symbol table is pushed onto a stack. When the closing curly brace is encountered, the scope is closed and the symbol table is popped. But that symbol table is remembered, rather than destroyed. And of course it remembers its higher level “parent” symbol table and so on.
Spaghetti Stacks are also used to implement Disjoint-set data structure.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Design and Implement Special Stack Data Structure | Added Space Optimized Version
- Decision Trees – Fake (Counterfeit) Coin Puzzle (12 Coin Puzzle)
- Interleave the first half of the queue with second half
- Next Greater Element
- Data Structure for Dictionary and Spell Checker?
- Number of elements greater than K in the range L to R using Fenwick Tree (Offline queries)
- Iterative Segment Tree (Range Minimum Query)
- Count inversions of size k in a given array
- Remove edges connected to a node such that the three given nodes are in different trees
- Sum of K largest elements in BST using O(1) Extra space