What is the time complexity of inserting into a linked list?

What is the time complexity of inserting into a linked list?

Approach: Distinguish between head and middle insertion.

O(1) if inserting at the head (given the pointer). O(n) if the insertion point must be found via traversal.

Follow-up: What is the complexity for a doubly linked list if you have the tail pointer?

Key concepts: pointers, traversal.