45 Questions
What operation initializes an empty stack?
new()
If you perform the operations push(10), push(5), and push(15) on an initially empty stack, what is the current size of the stack?
3
What does the pop() operation do in a stack?
Removes the top element from the stack
Which operation is used to view the top element of the stack without removing it?
peek()
Why should the remove methods inherited from Vector never be used in a Stack implementation?
They violate LIFO guarantee
Which method returns an iterator over the items contained in a stack, and why is the iterator's remove() method not supported?
iterator(); It violates a stack's basic contract
What does the clear() method do in a StackADT implementation?
Resets the stack to its initial state
How is the search method in StackADT different from zero-based positions?
It starts from position 1
Which method returns an iterator over the items contained in a stack, and why is the iterator's remove() method not supported?
iterator(); It violates a stack's basic contract
What is a fundamental requirement of a StackADT?
Ability to create an empty stack
Which operation must be supported by a StackADT to add an element to the top of the stack?
Push
What is a key capability of a StackADT related to accessing elements?
Ability to peek the topmost element without removing it
What is a requirement for a StackADT?
It must be possible to create an empty stack
What operation is used to add an element to the top of a stack?
push
What is the purpose of the 'peek' operation in a stack?
To access the topmost element without removing it
What is a common application of a stack for interpreters like the Java Virtual Machine?
Maintaining a stack containing intermediate results during evaluation of complicated expressions
What is the role of a stack for parsers like compilers during the parsing process?
Maintains a stack containing symbols encountered during parsing
What is the function of a stack for backtrackers like undo and redo operations?
It provides an alternative to recursion
What happens every time a method is called in the context of the call stack?
An activation record is created and pushed onto the call stack
Where is the main() method located in the call stack?
At the bottom of the stack
What happens when a method finishes execution and returns control to the calling method?
The activation record is popped off the stack
In a queue, where can elements be added and removed?
Added at the tail and removed at the head
What is the length of an empty queue?
Zero
What type of sequence is a queue?
First-in-first-out (FIFO)
What is the key characteristic of a queue?
Elements are added at one end and removed at the other end
What is the length of an empty queue?
Zero
How is the length of a queue defined?
Number of elements it contains
What is a fundamental requirement of a QueueADT?
It must be possible to create an empty queue
What operation must be supported by a QueueADT to add an element to the end of the queue?
Enqueue
What should be possible in a QueueADT without removing the first element from the queue?
Peek the first element in a queue
What is the correct order of operations in the example
new(), enqueue(10), enqueue(5), enqueue(15), dequeue(), peek(), dequeue()
Quantos elementos es in le queue post le operation 'dequeue()'?
2
What is the result of 'peek()' after the 'dequeue()' operation?
5
What is a common application that requires preserving the order of insertion?
Print servers
Which application maintains a queue of HTTP requests?
Web servers
What type of applications maintain a queue of objects and events for processing?
Simulations
Which application maintains a queue of print jobs?
Print servers
What type of applications require preserving the order of insertion?
Simulations
Which application maintains a queue of key presses?
Keyboard buffers
Which method is not supported by the iterator returned from the iterator() method in a QueueADT implementation?
add()
What method is used to check if a queue is full in a QueueADT implementation?
isFull()
Which method is used to remove all elements from a queue in a QueueADT implementation?
dequeueAll()
What method is used to return an array containing all of the items in a queue?
toArray()
Which method is not supported for the iterator over the items contained in a queue?
remove()
What method is used to check if the queue is full in a fixed-size queue implementation?
isFull()
Test your knowledge of basic stack operations with this quiz. Answer questions about stack initialization, size after pushing elements, and the effects of pop() operation. See how well you understand the fundamental concepts of stacks.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free