A singly linked list is a sequence of nodes, where each node contains a value and refers to the next node. Elixir lists use this recursive structure, so traversal proceeds from the head toward the tail. section 2.4.4
The representation makes some operations natural and others expensive:
- Prepending uses the cons form [head | tail] and adds an element without traversing the existing list. section 2.4.4
- Finding an element, calculating length, accessing by index, replacing, inserting, appending, and concatenating generally require traversal and have O(n) complexity. section 2.4.4
- Choose tuples, maps, or a higher-level data structure when direct access is required. section 2.4.4
Decomposing and extending a list
Pattern matching exposes the first element and the remainder: a_list = [head | tail]. The same structure supports construction, as in [:new_element | a_list], which prepends without mutating the original binding.
View the recursive structure of [1, 2, 3, 4] as nested head-and-tail links. section 2.4.4







