COMS2004 - Stacks and Queues

Which are stack operations?
Click the card to flip 👆
1 / 23
Terms in this set (23)
Stack or Queue? Teacher marking the exams on their desk that were placed there by the students after they were done writing.StackStack or Queue? Adding posts to a social media story or status that expires and is removed after 24 hours.QueueWhen you arrive at the bank, they give out a number, and the system will call out that number when it's your time to be served. Which data structure is convenient to implement such a system.?QueueWhich is the correct output for the following sequence of queue operations: 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().5,3,2,8,9,1,7,6Which data structure would be better suited to reversing a text string?StackWhat is the minimum number of stacks needed to implement a queue? Consider the situation where no other abstract data structures like arrays, linked lists, heaps, etc is available to you.2Suppose you have a deque D containing the numbers (1,2,3,4,5,6,7,8), in this order. Suppose further that you have an initially empty queue Q. Select a pseudo-code description of a function that uses only D and Q (and no other variables or objects) and results in D storing the elements (1,2,3,5,4,6,7,8), in this order.D:addBack(D:removeFront()) D:addBack(D:removeFront())D:addBack(D:removeFront()) Q:enqueue(D:removeFront()) Q:enqueue(D:removeFront()) D:addFront(Q:dequeue()) D:addFront(Q:dequeue()) D:addFront(D:eraseBack()) D:addFront(D:eraseBack()) D:addFront(D:eraseBack())What scheme do queues follow for insertions and deletions?First in first outWhat are the two main operations of the stack?push and popSuppose an initially empty stack S has performed a total of 25 push operations, 12 top operations, and 10 pop operations (not necessarily in this order), 3 of which generated a StackEmpty exception that was caught and ignored. What is the current size of S?18Musa has three array-based stacks, A, B, and C, such that A has capacity 100, B has capacity 5, and C has capacity 3. Initially, A is full, and B and C are empty. Unfortunately, the person who programmed the class for these stacks made the push and pop functions private. The only function Musa can use is a static function, transfer(S,T), which transfers (by incrementally applying the private pop and push functions) elements from stack S to stack T until either S becomes empty or T becomes full. So, for example, starting from our initial configuration and performing transfer(A,C) results in A now holding 97 elements and C holding 3. Help Musa by providing a sequence of transfer operations starting from the initial configuration and results in B holding 4 elements at the end.transfer(A,B);transfer(B,C);transfer(C,A);transfer(B,C);transfer(A,B);transfer(B,C)What are the direct applications of the queue?a. Access to shared resources (e.g. Printers) b. Multiprogramming c. Waiting listsStacks are also known as ...Last in first out