Q. If a stack is implemented using a linked list, what is the time complexity of the 'pop' operation?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
The 'pop' operation in a stack implemented using a linked list is done in constant time, O(1), as it involves removing the head node.
Correct Answer:
A
— O(1)
Learn More →
Q. In a stack, what is the time complexity of the 'top' operation?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
The 'top' operation in a stack, which retrieves the top element without removing it, has a time complexity of O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of clearing all elements from a stack?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
Clearing all elements from a stack requires popping each element, leading to a time complexity of O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of dequeuing an element from a queue implemented using a circular array?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
Dequeuing an element from a queue implemented using a circular array can be done in constant time, O(1), as it involves adjusting the front index.
Correct Answer:
A
— O(1)
Learn More →
Q. What is the worst-case time complexity for searching an element in a queue?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
In a queue, searching for an element requires traversing the entire queue, leading to a worst-case time complexity of O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. Which data structure allows for both LIFO and FIFO operations?
-
A.
Stack
-
B.
Queue
-
C.
Deque
-
D.
Array
Solution
A Deque (double-ended queue) allows for both LIFO (Last In First Out) and FIFO (First In First Out) operations.
Correct Answer:
C
— Deque
Learn More →
Q. Which of the following operations has a time complexity of O(n) in a stack?
-
A.
Push
-
B.
Pop
-
C.
Peek
-
D.
None of the above
Solution
All basic operations (Push, Pop, Peek) in a stack have a time complexity of O(1). Therefore, the correct answer is 'None of the above'.
Correct Answer:
D
— None of the above
Learn More →
Showing 1 to 7 of 7 (1 Pages)