Question: In this question, I think I only need a counter that adds when it meets an integer and substracts when it meets a minus sign,

In this question, I think I only need a counter that adds when it meets an integer and substracts when it meets a minus sign, right?
But I don't quite understand the meaning of linear-time algorithm, and the constrain in the brackets.
Can someone help me ?
1.3.45 Stack generability. Suppose that we have a sequence of intermixed push and pop operations as with our test stack client, where the integers 0, 1,.., n-1 in that order (push directives) are intermixed with n minus signs (pop directives). Devise an algo- rithm that determines whether the intermixed sequence causes the stack to underflow. e only an amount of space independent of n-you cannot store the integers in a data structure.) Devise a linear-time algorithm that determines whether a given permutation can be generated as output by our test client (depending on where the pop directives occur)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
