Search code examples
pythondata-structurestime-complexityruntimedoubly-linked-list

Is the runtime of comparing two nodes and then removing Θ(1)?


So the data structure in question is a doubly linked list.

Let's say that we needed to compare the data of node next to the header and data of the node next to the trailer. Then, depending on which node's data was bigger, we remove the node with bigger data.

Does this entire process take up Θ(1) time, or is it more complex than that?


Solution

  • Yes, it is O(1) because you access the head and tail directly.