Q: What is the time complexity of appending an element to the end of a dynamic array, assuming sufficient capacity is available?
-
A
O(n)
-
B
O(1)
-
C
O(log n)
-
D
O(n log n)
B
Answer:
B
Explanation:
When appending an element to the end of a dynamic array with sufficient capacity, the operation can be performed in constant time. This is because the dynamic array allocates extra space to accommodate additional elements, and appending a new element simply requires placing it at the next available index. The time complexity of this operation is constant, denoted as O(1).
Related Topic:
Share Above MCQ