One thing which the OP didn't specify is if he was interested in the generic linked list data structure or in std::list and std::forward_list. For the standard containers, the complexity is actually shown in the description of each method.
I think the real killer is iteration. For me, iteration is the most frequent thing that happens, whereas insertions and removals are comparatively rare. |
And this is why complexity is broken down into individual operations. If I am creating a stack or queue, I am interested in the complexity for insertions and removals, not iterations or searches or "random insertion".
If linked-list insertion complexity was a linear O(n) because it included an unnecessary search complexity as the OP wondered about, that would be misleading.
Of course, for a sorted linked-list insertion, complexity would be linear because you simply can't insert a random item into a sorted linked-list without searching for a valid insertion point which would not break the sorted pattern.
Standard disclaimer for all things performance related ... complexity is only one factor affecting performance. Measure first, optimize later. Overhead may overwhelm complexity on smaller data sets. Thread safety, memory allocation, caching, spatiality, predictability, etc. may all affect performance.