A stack is a Last In First Out (LIFO) data structure. A common use of stacks is to store subroutine arguments and return addresses.

learn more… | top users | synonyms

4
votes
0answers
78 views

What techniques could be used to support thread-local contexts and resources in a language?

I am interested in the subject of thread-local contexts, which is a feature that I use quite often in solutions, but seems to lack first-class support in any languages I have used. Quite often in ...
1
vote
3answers
68 views

How are variables accessed in the correct order from the stack?

I'm learning about the stack but one thing I am unable to understand is how variables can be accessed in the correct order. So if I had a basic program calculating the sum of some user entered values ...
0
votes
1answer
32 views

Memory address of variable after reassignment

When a local variable is reassigned a different value/object, does its position/address change in the stack?
-1
votes
1answer
132 views

implementation of queue using stack with REVERSE

Suppose a stack implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. I'm looking for implementation ...
2
votes
1answer
470 views

Why do we use stacks and not queues on system-level?

From low OS-level function calls, to memory allocated to an application, all will primarily take a stack to perform LIFO operations. Why don't we use queues and FIFO operations? It's just a matter of ...
5
votes
1answer
128 views

Is a LBA with stack more powerful than a LBA without?

Even so a linear bounded automata (LBA) is strictly more powerful than a pushdown automata (PDA), adding a stack to a LBA might make it more powerful. A LBA with stack should not be Turing complete, ...
6
votes
2answers
393 views

Is a stack machine with a forward read iterator Turing complete?

It is well known that a machine with a single stack as only unlimited storage is not Turing complete, if it can only read from the top of the stack. I want a machine which is (slightly) more powerful ...
19
votes
1answer
2k views

Is a stack overflow detected by hardware or software?

Is it the task of the software (operating system) to detect stack overflows or is a stack overflow detected in hardware, causing an exception in the CPU?
-1
votes
1answer
62 views

Collecting and combining data from iterative DFS on read-only trees

I am iterating over a tree through an API. This API provides a list of nodes sorted in post order DFS. I need to gather data for each node in the tree, combine that data with the parent's data ...
2
votes
2answers
69 views

Stack memory questions

Are data and return addresses both pushed on the same stack space? If yes, couldn't this piece of code cause problems: ...
5
votes
2answers
891 views

Data Structure for Representing a Math Expression

I'm looking to improve my object-oriented design skills and I came across a problem which asked to design classes to represent a mathematical expression such as (a + b) * ( c - d / e) in memory so ...
0
votes
1answer
100 views

Which permutations can not be obtained by moving elements through two stacks?

I have a Stack1 which has the entries a,b,c ( with a on the Top) and Stack2 which is empty.The condition is. An entry pooped out of the stack1 can be printed immediatly or pushed to stack2. An ...
2
votes
3answers
58 views

Recursive methods with stacks

I'm doing some practice papers for revision for my finals and I came across this question: "This question is about recursion. A recursive method can always be implemented by an iterative method ...
3
votes
1answer
61 views

Is “duplicate” in RPN enough for replacing variable binding in term expressions?

I try to work out some consequences of storing (or "communicating"/"transmitting") a rational number by a term expression using the following operators: $0$, $\mathsf{inc}$, $\mathsf{add}$, ...
-1
votes
1answer
266 views

What are activation records?

What are the open activation records of a recursive algorithm ? Edit: Activation records are the number of times that we call a function that is not finished yet. Correct? So we can find the number ...
4
votes
4answers
160 views

Interleaving algorithm for 2 stacks

Suppose I have two stacks $<a_1,a_2,...a_m>$ and $<b_1, b_2,...b_n>$ and a third stack of size $m+n$. I want to have the third stack in the following manner, ...
1
vote
2answers
62 views

“Minimum Stack”

I am now preparing for a test in my algorithms course and I have stumbled upon a question about a data structure which seems too trivial for me, but is probably not trivial at all. The question is: ...
1
vote
1answer
36 views

How to get a base-3 representation of an integer using a stack? [closed]

Assuming that a stack data structure is available, how can this data structure be used to compute a representation of an integer in base three? For example, the algorithm for ...
4
votes
2answers
114 views

Does the OS create its own bootstrapped stack frame when running a program?

I've been doing nand2tetris exercises and I'm quite interested in how compilation actually works. In nand2tetris when creating the VM language I had to create a "bootstrap" which called the main ...
1
vote
0answers
20 views

Impelementing a stack using a 2 queues, and a queue using 2 stacks [duplicate]

I have thought about it for a while, and I'm not really sure what is the best way to: 1.Implement a stack using 2 queues. 2.Implement a queue using 2 stacks. I have only though about ...
13
votes
5answers
5k views

How to implement two stacks in one array?

I want to begin by saying that this is NOT a homework question. I am reading Introduction to Algorithms - the famous CLRS text to become a better programmer. I am trying to solve the problems and ...
1
vote
1answer
724 views

Efficient algorithm for a modified stack to pop the smallest element

I was practicing the following problem : There are a total of $N$ operations. At each operation, you can either add an element to the top or remove several elements as described below. ...
1
vote
1answer
201 views

A puzzle in Permutation

There are two stacks A and B. A : a,b,c,d ('a' is on top and 'd' is at the bottom of the stack) B : (empty) There are two rules. ...
1
vote
2answers
153 views

Using Queues for a Stack and Stacks for a Queue

I was asked a question on how to use a pair of Queues to create a Stack and how to use a pair of Stacks to create a Queue. Any thoughts on how I would do this? Right now I don't even know where to ...
7
votes
1answer
261 views

How to detect stack order?

We take the sequence of integers from $1$ to $n$, and we push them onto a stack one by one in order. Between each push, we can choose to pop any number of items from the stack (from 0 to the current ...
24
votes
1answer
891 views

Is there a 'string stack' data structure that supports these string operations?

I'm looking for a data structure that stores a set of strings over a character set $\Sigma$, capable of performing the following operations. We denote $\mathcal{D}(S)$ as the data structure storing ...