Skip to content

Time & Space Complexity


OperationSingly Linked ListWhy?
Get the Nth itemO(n)Must walk from head
Search for valueO(n)Must check each node
Insert at startO(1)Just rewire head
Insert at endO(n)Walk to last node
Insert at middleO(n)Walk to position, then O(1)
Delete from startO(1)Just move head forward
Delete from endO(n)Walk to find 2nd last
Delete by valueO(n)Search + delete
ReverseO(n)Single pass through list

Space Complexity: O(n) for n nodes (plus O(1) extra for temporary pointers during operations).


OperationDoubly Linked ListWhy?
Insert at startO(1)Update head and prev pointers
Insert at endO(1) (with tail pointer)Direct access to tail
Delete at endO(1) (with tail pointer)Use tail.prev to update
Delete given nodeO(1)Node has direct access to prev
All other operationsO(n)Same traversal cost

Note: Doubly linked lists use O(n) memory as well, but with roughly 2× the constant factor due to the extra prev pointer per node.


Use Linked List when…Use Array when…
You add/remove at the start a lotYou need fast random access (arr[5])
You don’t know how big it’ll getMemory matters (cache friendly)
You’re building stacks/queuesYou do lots of math/range queries
Memory fragmentation is okayYou need bidirectional traversal
You need constant-time deletionsData size is fixed/predictable

Arrays Singly LL Doubly LL
Access ──── O(1) ── O(n) ── O(n)
Search ──── O(n) ── O(n) ── O(n)
Ins Beg ── O(n) ── O(1) ── O(1)
Ins End ── O(1)* ── O(n) ── O(1)†
Del Beg ── O(n) ── O(1) ── O(1)
Del End ── O(1)* ── O(n) ── O(1)†
* Amortized / with capacity
† With tail pointer