Difficulty of time for insertion / deletion in a doubly linked list of order O (n)?

To insert / remove a node with a specific value in a DLL (a doubly linked list), you need to go through the entire list to find the location, so these operations must be O (n).

If so, why is the STL list (most likely implemented using the DLL) able to provide these operations in constant time?

Thanks to everyone for letting me know.

+3
source share
3 answers

Insert and remove in a known position - O (1). However, find this position O (n) if it is not the head or tail of the list.

, , , .

+12

. STL , , , , ARE O(1), . O(n).

+2

( node) O (n), . node (.. node), O (1).

- . - O (n). , node O (1).

O (1) - .

+1
source

Source: https://habr.com/ru/post/1768827/


All Articles