Linked List – Why Linked List Implementation is Considered Linear

data structures

Typically, computer memory is always linear. So is the term non linear used for a data structure in a logical sense? If so, to logically achieve non linearity in a linear computer memory, we use pointers. Is that right?

In that case, if pointers are virtual implementations for achieving non linearity, why would a data structure like linked list be considered linear, if in reality the nodes are never physically adjacent?

Best Answer

I think what they mean by "linear" is most probably the linked list's performance characteristics. To access the n-th element of a linked list, you need to walk through each element before it one by one. Thus, the time required to do this is a linear function of n (the upper limit of which is the list size). As opposed to e.g. an array, which is random access, i.e. accessing any array element by index requires practically the same, constant time.

OTOH inserting a new element in a known location in the middle of a linked list requires constant time, while doing the same in an array requires shifting the remainder of the array in memory, which is linear to number of subsequent elements (bounded by the size of the array). So linked lists do have performance benefits.