Michael Xia
Michael Xia

Reputation: 464

Deque (time complexity)

What is the time complexity for accessing deque[0], deque[somewhere in the middle], and deque[-1]?

Upvotes: 2

Views: 742

Answers (1)

Barmar
Barmar

Reputation: 782785

From the documentation:

Indexed access is O(1) at both ends but slows to O(n) in the middle. For fast random access, use lists instead.

This suggests that the implementation is a doubly-linked list.

Upvotes: 5

Related Questions