Q. In a stack, what is the result of the operation 'push(5)', followed by 'push(10)', and then 'pop()'?
-
A.
5
-
B.
10
-
C.
Both 5 and 10
-
D.
Stack is empty
Solution
The 'pop()' operation will return 10, as it is the last element pushed onto the stack.
Correct Answer:
B
— 10
Learn More →
Q. In which scenario would you prefer using a stack over a queue?
-
A.
When you need to process tasks in the order they arrive
-
B.
When you need to backtrack through a series of operations
-
C.
When you need to manage tasks with priority
-
D.
When you need to store data persistently
Solution
Stacks are useful for backtracking scenarios, such as undo operations in applications.
Correct Answer:
B
— When you need to backtrack through a series of operations
Learn More →
Q. What happens when you try to pop an element from an empty stack?
-
A.
It returns null
-
B.
It throws an exception
-
C.
It returns the last element added
-
D.
It does nothing
Solution
Attempting to pop from an empty stack typically results in an exception being thrown.
Correct Answer:
B
— It throws an exception
Learn More →
Q. What is the main difference between a stack and a queue?
-
A.
Stack is LIFO, Queue is FIFO
-
B.
Stack is FIFO, Queue is LIFO
-
C.
Both are LIFO
-
D.
Both are FIFO
Solution
The main difference is that a stack operates in a Last In First Out (LIFO) manner, while a queue operates in a First In First Out (FIFO) manner.
Correct Answer:
A
— Stack is LIFO, Queue is FIFO
Learn More →
Q. Which of the following is a common application of a queue?
-
A.
Function call management
-
B.
Undo functionality in text editors
-
C.
Breadth-first search in graphs
-
D.
Expression evaluation
Solution
Queues are commonly used in breadth-first search algorithms to manage the nodes to be explored.
Correct Answer:
C
— Breadth-first search in graphs
Learn More →
Q. Which of the following operations can be performed in constant time on a queue?
-
A.
Enqueue
-
B.
Dequeue
-
C.
Peek
-
D.
All of the above
Solution
All of the operations (Enqueue, Dequeue, and Peek) can be performed in constant time, O(1), in a properly implemented queue.
Correct Answer:
D
— All of the above
Learn More →
Q. Which of the following operations is NOT typically associated with a queue?
-
A.
Enqueue
-
B.
Dequeue
-
C.
Peek
-
D.
Push
Solution
The 'Push' operation is associated with stacks, while queues use 'Enqueue' to add and 'Dequeue' to remove elements.
Correct Answer:
D
— Push
Learn More →
Showing 1 to 7 of 7 (1 Pages)