Question

In: Computer Science

Suppose an initially empty stack S has performed a total of 15 push operations, 12 top...

Suppose an initially empty stack S has performed a total of 15 push operations, 12 top operations, and 13 pop operations ( 3 of which returned null to indicate an empty stack ). What is the current size of S?

Question 1 options:

Question 2 (1 point)

Saved

What values are returned during the following series of stack operations, if executed upon an initially empty stack? push(5), push(3), pop(), push(2), push(8), pop(), pop(), push(9), push(1), pop(), push(7), push(6), pop(), pop(), push(4), pop(), pop().

seperate by commas ie: 1, 2, 3, 4, 5, 6, 7, 8, 9

Question 2 options:

Question 3 (1 point)

Saved

What values are returned during the following sequence of queue operations, if executed on an initially empty queue? enqueue(5), enqueue(3), dequeue(), enqueue(2), enqueue(8), dequeue(), dequeue(), enqueue(9), enqueue(1), dequeue(), enqueue(7), enqueue(6), dequeue(), dequeue(), enqueue(4), dequeue(), dequeue().

seperate by commas ie: 1, 2, 3, 4, 5, 6, 7, 8, 9

Question 3 options:

Question 4 (1 point)

Saved

What values are returned during the following sequence of deque ( double ended queue ) ADT operations, on an initially empty deque? addFirst(3), addLast(8), addLast(9), addFirst(1), last( ), isEmpty( ), addFirst(2), removeLast( ), addLast(7), first( ), last( ), addLast(4), size( ), removeFirst( ), removeFirst( ).

seperate by commas ie: 1, 2, 3, 4, 5, 6, 7, 8, 9

Question 4 options:

Question 5 (1 point)

Saved

Suppose an initially empty queue Q has performed a total of 30 enqueue operations, 10 first operations, and 15 dequeue operations, 5 of which returned null to indicate an empty queue. What is the current size of Q?

Question 5 options:

Solutions

Expert Solution

Question1 Answer:

A push operation inserts an item into the stack and a pop deletes an item from the stack. A top operation doesn't delete any item but just tells the value of top element in stack.

Now, 15 push, 12 top and 13 pop operations are performed. These are not necessarily sequential but can be in mixed order. For example, first we push 3 elements and then pop 4 elements. On the 4th pop, null will be returned to indicate empty stack.

In total, out of 13 pop operations, 3 are wasted as null is returned. So, at the end, there will be 15 - (13 - 3) elements in stack i.e 5 elements

Question2 answer:

push(5), push(3), pop(), push(2), push(8), pop(), pop(), push(9), push(1), pop(), push(7), push(6), pop(), pop(), push(4), pop(), pop().

The returned values are 3,8,2,1,6,7,4,9

Question 3 answer:

enqueue(5), enqueue(3), dequeue(), enqueue(2), enqueue(8), dequeue(), dequeue(), enqueue(9), enqueue(1), dequeue(), enqueue(7), enqueue(6), dequeue(), dequeue(), enqueue(4), dequeue(), dequeue().

The returned values are 5,3,2,8,9,1,7,6

Question 5 Answer:

An enqueue operation inserts an item into the queue and a dequeue operation deletes an item from the queue. A first operation doesn't delete any item but just tells the value of first element in the queue.

Now, 30 enqueue operations, 10 first operations, and 15 dequeue operations are performed. These are not necessarily performed sequentially but can be in mixed order. For example, first we enqueue 3 elements and then dequeue 4 elements. On the 4th dequeue, null will be returned to indicate empty queue.

In total, out of 15 dequeue operations, 5 are wasted as null is returned. So, at the end, there will be 30 -(15 - 5) elements in the queue i.e 20 elements in the queue.


Related Solutions

Reverse the contents of a stack using only stack operations [ push() and pop()  ]. Using the...
Reverse the contents of a stack using only stack operations [ push() and pop()  ]. Using the java and give the explanation
5 marks] A MinStack supports three main operations: the standard Stack operations push(x) and pop() and...
5 marks] A MinStack supports three main operations: the standard Stack operations push(x) and pop() and the non-standard min() operation which returns the minimum value stored on the stack. The zip file gives an implementation SlowMinStack that implements these operations so that push(x) and pop() each run in O(1) time, but  min()runs in Θ(n) time. For this question, you should complete the implementation of FastMinStack that implements all three operations in O(1) time per operation. As part of your implementation, you...
The following equation has been estimated: stack s a t with hat on top =1028.10+19.3 hsize-1.90...
The following equation has been estimated: stack s a t with hat on top =1028.10+19.3 hsize-1.90 hsize_squared-53.29 female-156.26 black+37.87 female*black (6.29) (3.83) (0.53) (4.29) (14.66) (18.15) The variable sat is the combined SAT score, hsize is the size of the students' high school graduating class in hundreds. The variable female is a gender dummy variable equal to 1 for females and 0 otherwise. Another variable black is a race dummy variable equal to 1 for black and 0 otherwise. Robust...
if S is non empty and it has a lower bound, then it has an infimum, inf S
  if S is non empty and it has a lower bound, then it has an infimum, inf S Start of proof: b<=s for all s in S LB: {y in R:y<=S, for all s in S} LB is bounded above by X and LB is non empty since b is in LB Find supLB=infS, thats what needs to be completed
Suppose a nation has a total of 12 units of labor, whichcan be used to...
Suppose a nation has a total of 12 units of labor, which can be used to produce either guns or butter. One gun takes 6 units of labor to produce and 1 butter takes 2 units of labor to produce. Use the information to create a table showing the different combinations of guns and butter that can be produced. Explain why scarcity exists in this economy. Use the data as evidence of your reasoning. What is the maximum quantity of...
Suppose the water at the top of Niagara Falls has a horizontal speed of 1.20 m/s...
Suppose the water at the top of Niagara Falls has a horizontal speed of 1.20 m/s just before it cascades over the edge of the falls. At what vertical distance below the edge does the velocity vector of the water point downward at a 47.3 ° angle below the horizontal?
An object is initially traveling at a velocity of 12 m/s. It then begins to change...
An object is initially traveling at a velocity of 12 m/s. It then begins to change it’s velocity according to the function ?=2.5?+3? v = 2 . 5 s + 3 a , where v is the velocity of the object, s is the objects position, and a is the acceleration. Determine the velocity of the object 30 meters after the velocity begins to change. (17.5 m/s)
Suppose you start with an empty queue and perform the following operations: enqueue 1, enqueue 2,...
Suppose you start with an empty queue and perform the following operations: enqueue 1, enqueue 2, dequeue, enqueue 3, enqueue 4, dequeue, enqueue 5. What are the resultant contents of the queue, from front to back? Group of answer choices 1, 2, 3, 4, 5 1, 3, 5 1, 2, 3 3, 4, 5 Assume you are using the text's array-based queue and have just instantiated a queue of capacity 10. You enqueue 5 elements, dequeue 4 elements, and then...
A crate is given a push such that it has an initial speed of 5.2 m/s...
A crate is given a push such that it has an initial speed of 5.2 m/s headed up a 15 degree incline. If the crate travels 3.5m up the incline before reversing direction, what is the coefficient of kinetic friction between the crate and the incline?
A loop has a radius of 15 centimeters and it is initially in the plane of...
A loop has a radius of 15 centimeters and it is initially in the plane of your screen. A constant magnetic field is pointing out of the screen and has a value of 1T. The loop then rotates by 45º along a vertical axis (so it's partially sticking out of your screen). It takes 4.8 seconds to rotate. Determine the electromotive force (the voltage) that will be generated in the process (express your answer in mV)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT