A Singly Linked List
Definition: A collection of elements stored together in a linked, linear format where each piece of data contains a reference to the next piece of data in the list (or in the case of a doubly linked list, next and previous). Linked Lists are not indexed like arrays. There are 3 main types of Linked Lists:
Real Life Example: A conga line! Everyone in the line is connected to the person in front of them with their hands. When someone joins or leaves the line, people affected by the change must reconnect their hands so that the line stays intact.
Note: The first node in a linked list (the one farthest to the left with no other nodes pointing to it) is called the head. The last node is a linked list (the one farthest to the right that points to null) is called the tail.
Basic Singly Linked List Operations:
Fun Fact #1: Unlike in a graph, a node in a Linked List consists of the data AND the arrow(s) stemming from it (but not the ones pointing towards it).
Fun Fact #2: In a singly linked list, the tail node points towards "null" (meaning empty) to signify the end of the Linked List. This is necessary because searching a Linked List is done by following the "arrows" node by node (much slower than in an array) and without "null", there is no instruction for the search to stop once it reaches the final node. The same goes for doubly linked lists except a "null" value is pointed to by the tail AND the head.
Commonly Used In:
Other Similar Data Structures: