Q. If a stack has a maximum size of 100 and you attempt to push 101 elements onto it, what will happen?
A.
The 101st element will be pushed successfully.
B.
An error will occur due to stack overflow.
C.
The stack will automatically resize.
D.
The stack will discard the oldest element.
Show solution
Solution
Attempting to push more elements than the maximum size of the stack will result in a stack overflow error.
Correct Answer:
B
— An error will occur due to stack overflow.
Learn More →
Q. In a priority queue implemented with a binary heap, what is the time complexity for inserting an element?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
Inserting an element into a binary heap takes O(log n) time due to the need to maintain the heap property after the insertion.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the main disadvantage of using a linked list to implement a stack?
A.
Higher memory usage per element
B.
Slower access time
C.
Complexity of implementation
D.
No disadvantages
Show solution
Solution
The main disadvantage of using a linked list to implement a stack is the higher memory usage per element due to the storage of pointers in addition to the data.
Correct Answer:
A
— Higher memory usage per element
Learn More →
Q. Which of the following statements about stacks is true?
A.
Stacks can be implemented using arrays or linked lists.
B.
Stacks allow random access to elements.
C.
Stacks are FIFO data structures.
D.
Stacks can only store integers.
Show solution
Solution
Stacks can indeed be implemented using both arrays and linked lists, while they follow LIFO (Last In, First Out) order.
Correct Answer:
A
— Stacks can be implemented using arrays or linked lists.
Learn More →
Showing 1 to 4 of 4 (1 Pages)