what are my options? I need to call a lot append(on the right) and popleft(naturally, from the left end), but also read from the middle of the repository, which will grow steadily, by the nature of the algorithm. I would like to have all these operations in O(1).
I could implement it in C quite easily in an array with a circular address (what is this word?), Which would automatically increase when it is populated; but what about python? Pointers to other languages are also appreciated (I understand that the “collection” tag is more oriented to Java, etc., and he would appreciate the comparison, but as a secondary goal).
I came from the background of Lisp and was amazed to learn that in Python, removing the head element from the list is an operation O(n). A dequemay be the answer, except for the documentation according to which access is O(n)in the middle. Is there anything else pre-built?
source
share