Question

In: Computer Science

Letters are pushed on a stack in order: R A N D O M O P...

Letters are pushed on a stack in order: R A N D O M O P S. Specify where to insert pop operations (shown by ‘*’) among the pushes of the given letters, in order to produce the output: ADONOMSPR . You can only do this process once. That is, you cannot take the output produced and then pass it again through the stack.

Solutions

Expert Solution

Pop() operation should be performed after the insetion of 'R' in the sequence.

i.e.

Initially Stack is empty, after that steps are as follows:

Step 1 : Push R Stack : R     Remaining elements : A N D O M O P S

Step 2 : Pop R Stack : 'Empty'    Remaining elements : A N D O M O P S R

Step 3 : Push A Stack : A Remaining elements : N D O M O P S R

Step 4 : Push N Stack : A N   Remaining elements : D O M O P S R

Step 5 : Push D Stack : A N D Remaining elements : O M O P S R

Step 6 : Push O Stack : A N D O Remaining elements : M O P S R

Step 7 : Push M Stack : A N D O M    Remaining elements : O P S R

Step 8 : Push O Stack : A N D O M O    Remaining elements : P S R

Step 9 : Push P Stack : A N D O M O P Remaining elements : S R

Step 10 : Push S Stack : A N D O M O P S Remaining elements : R

Step 11 : Push S Stack : A N D O M O P S R Remaining elements : 'Empty'

-----------------------------------

Explanation : Here we need to apply Pop Operation after the first Push operation and then R will pop out and go down to the end of the list of remaining elements and then push regularly to get the desired output.


Related Solutions

How many permutations of the letters m, n, o, p, q contain the string mn or...
How many permutations of the letters m, n, o, p, q contain the string mn or the string mo or the string op-last year exam?
Show that if P;Q are projections such that R(P) = R(Q) and N(P) = N(Q), then...
Show that if P;Q are projections such that R(P) = R(Q) and N(P) = N(Q), then P = Q.
Prove via induction the following properties of Pascal’s Triangle: •P(n,2)=(n(n-1))/2 • P(n+m+1,n) = P(n+m,n)+P(n+m−1,n−1)+P(n+m−2,n−2)+···+P(m,0) for all...
Prove via induction the following properties of Pascal’s Triangle: •P(n,2)=(n(n-1))/2 • P(n+m+1,n) = P(n+m,n)+P(n+m−1,n−1)+P(n+m−2,n−2)+···+P(m,0) for all m ≥ 0
a box of mass m = 66.0 kg (initially at rest) is pushed a distance d...
a box of mass m = 66.0 kg (initially at rest) is pushed a distance d = 54.0 m across a rough warehouse floor by an applied force of FA = 218 N directed at an angle of 30.0° below the horizontal. The coefficient of kinetic friction between the floor and the box is 0.100. Determine the following. (For parts (a) through (d), give your answer to the nearest multiple of 10.) * I already solved parts b and c...
Amron Ltd has three production departments: M, N, and O and two service departments P and...
Amron Ltd has three production departments: M, N, and O and two service departments P and Q. The following particulars are available for the month of March 2020: Particulars Amount ($) Lease rental 35,000 Industrial power and fuel 420,000 Wages to supervisor of production departments 6,400 Electricity 5,600 Depreciation on machinery 16,100 Depreciation on building 18,000 Payroll expenses 21,000 Canteen expenses 28,000 Superannuation contribution 58,000 Further information regarding the above indirect expenses are as follows: Particulars M N O P...
Consider the following economy with: Real Money demand 〖 (M/P)〗^d = – 12 R + 0.38...
Consider the following economy with: Real Money demand 〖 (M/P)〗^d = – 12 R + 0.38 Y Real Money supply (M^s/P)= 4510 Derive the LM curve Derive the LM curve when the money supply increases by 680. Derive the LM curve when money supply decreases by 12% Compare the LM curves from a, b and c by graphing them using any graphing tool (excel preferably). Comment on the differences. Find the value of money demanded when income Y = 15,000...
The third order rate coefficient for: O + O2 + M   -> O3 + M is...
The third order rate coefficient for: O + O2 + M   -> O3 + M is given by the expression: k = 6.0x10-34 *(T/300)-2.4 cm6 molecule-2 s-1 This reaction is in the low pressure, i.e. termolecular, limit under all atmospheric conditions. 1) Find the effective bimolecular rate at 220K and a pressure of 50 mbar 2) An O2 molecule undergoes photolysis giving O3P Find the pseudo-first order rate of O3 formation at 220K and a pressure of 50 mbar. What...
a) Verify that the indicial equation of Bessel's equation of order p is (r-p)(r+p)=0 b) Suppose...
a) Verify that the indicial equation of Bessel's equation of order p is (r-p)(r+p)=0 b) Suppose that p is not an integer. Carry out the computation to obtain the solutions y1 and y2 above.
2. Let D be a relation on the natural numbers N defined by D = {(m,n)...
2. Let D be a relation on the natural numbers N defined by D = {(m,n) : m | n} (i.e., D(m,n) is true when n is divisible by m. For this problem, you’ll be proving that D is a partial order. This means that you’ll need to prove that it is reflexive, anti-symmetric, and transitive. (a) Prove that D is reflexive. (Yes, you already did this problem on one of the minihomework assignments. You don’t have to redo the...
Find the half-range cosine series for the function f(x) = x(n - r) in o<r<n. Deduce...
Find the half-range cosine series for the function f(x) = x(n - r) in o<r<n. Deduce that 1/14 +1/24 +1/34+…. =π4 /90. 
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT