Q. In which scenario would you prefer using a queue over a stack?
-
A.
When you need to reverse elements
-
B.
When you need to process elements in the order they were added
-
C.
When you need to access the last added element
-
D.
When you need to sort elements
Solution
A queue is preferred when processing elements in the order they were added (FIFO), such as in task scheduling.
Correct Answer:
B
— When you need to process elements in the order they were added
Learn More →
Q. What is the average time complexity for searching an element in a stack?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
Searching for an element in a stack has an average time complexity of O(n) because you may need to traverse the entire stack.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of enqueueing an element in a queue implemented using an array?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
Enqueueing an element in a queue implemented using an array can be done in constant time, O(1), if there is space available.
Correct Answer:
A
— O(1)
Learn More →
Q. What is the worst-case time complexity for accessing an element in a queue implemented using a linked list?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
Accessing an element in a queue implemented using a linked list has a worst-case time complexity of O(n) because you may need to traverse the list.
Correct Answer:
B
— O(n)
Learn More →
Q. Which of the following is a common application of a stack?
-
A.
Undo functionality in text editors
-
B.
Managing tasks in a queue
-
C.
Storing elements in sorted order
-
D.
Finding the shortest path in a graph
Solution
Stacks are commonly used for undo functionality in text editors, as they allow the last action to be reversed easily.
Correct Answer:
A
— Undo functionality in text editors
Learn More →
Q. Which of the following operations is not typically associated with a stack?
-
A.
Push
-
B.
Pop
-
C.
Peek
-
D.
Dequeue
Solution
Dequeue is not associated with a stack; it is an operation related to queues.
Correct Answer:
D
— Dequeue
Learn More →
Showing 1 to 6 of 6 (1 Pages)