Question

In Python, which of the following built-in data structures can be most efficiently used to implement a stack, and why?

A list using append() and pop() from the end, due to O(1) average time complexity.
B collections.deque using append() and popleft(), due to O(1) average time complexity.
C list using insert(0, item) and pop(0), due to O(1) average time complexity.
D tuple due to its immutability and fast access.
E set due to its unique element property.
Practice Next

Hey! Ask a query