Q. In a queue, what happens when an element is dequeued?
-
A.
It is removed from the front
-
B.
It is removed from the back
-
C.
It is moved to the front
-
D.
It is added to the back
Solution
In a queue, the dequeue operation removes the element from the front, following the FIFO principle.
Correct Answer:
A
— It is removed from the front
Learn More →
Q. In which scenario would you prefer a stack over a queue?
-
A.
When you need to process items in FIFO order
-
B.
When you need to backtrack through previous states
-
C.
When you need to store items for later retrieval
-
D.
When you need to manage multiple tasks simultaneously
Solution
Stacks are ideal for backtracking scenarios, such as navigating through a maze or undoing actions in applications.
Correct Answer:
B
— When you need to backtrack through previous states
Learn More →
Q. What data structure would you use to implement a printer queue?
-
A.
Stack
-
B.
Queue
-
C.
Linked List
-
D.
Array
Solution
A queue is used for printer queues because it processes print jobs in the order they are received (FIFO).
Correct Answer:
B
— Queue
Learn More →
Q. What is a common application of a stack in programming?
-
A.
Managing function calls
-
B.
Storing data in a linear fashion
-
C.
Implementing a priority queue
-
D.
Searching for elements
Solution
Stacks are commonly used to manage function calls in programming languages, where the last function called is the first to return.
Correct Answer:
A
— Managing function calls
Learn More →
Q. What is the primary advantage of using a stack for function calls?
-
A.
Memory efficiency
-
B.
Ease of implementation
-
C.
Automatic management of return addresses
-
D.
Faster execution time
Solution
Stacks automatically manage return addresses for function calls, allowing for easy backtracking to the previous state.
Correct Answer:
C
— Automatic management of return addresses
Learn More →
Q. Which application uses both stacks and queues?
-
A.
Depth-first search
-
B.
Breadth-first search
-
C.
Expression evaluation
-
D.
Memory allocation
Solution
Expression evaluation often uses stacks for operators and operands, while queues can be used for managing the order of operations.
Correct Answer:
C
— Expression evaluation
Learn More →
Q. Which of the following best describes a stack?
-
A.
First In First Out
-
B.
Last In First Out
-
C.
Random Access
-
D.
Ordered Collection
Solution
A stack operates on a Last In First Out (LIFO) principle, meaning the last element added is the first one to be removed.
Correct Answer:
B
— Last In First Out
Learn More →
Q. Which of the following is an application of a queue?
-
A.
Undo functionality in text editors
-
B.
Breadth-first search in graphs
-
C.
Expression evaluation
-
D.
Memory management
Solution
Queues are used in breadth-first search algorithms for traversing graphs, as they process nodes in the order they are discovered.
Correct Answer:
B
— Breadth-first search in graphs
Learn More →
Q. Which of the following operations is not typically associated with stacks?
-
A.
Push
-
B.
Pop
-
C.
Peek
-
D.
Enqueue
Solution
Enqueue is an operation associated with queues, while stacks use push, pop, and peek operations.
Correct Answer:
D
— Enqueue
Learn More →
Showing 1 to 9 of 9 (1 Pages)