Data Structures and Algorithms • C# examples
Singly, Doubly, and Circular Linked Lists
Understand node-based sequences and the difference between access and insertion costs.
Concept
A linked list stores values in nodes connected by references. It supports local insertion or removal efficiently when the relevant node is already known, but locating an index requires traversal. Doubly linked nodes support backward movement at the cost of an extra reference; circular lists connect the tail back to the head.
How to approach it
Track head, tail, and neighboring references explicitly; handle empty, one-node, and endpoint changes.
Complexity
Search/index access O(n); insertion after a known node O(1); node storage O(n).
C# example
sealed class Node<T>(T value)
{
public T Value { get; } = value;
public Node<T>? Next { get; set; }
}
Expected result or behavior
Each node holds one value and a reference to the next node.
Practice exercise
Draw the pointer updates required to remove a middle node from a doubly linked list.
Key takeaway: Linked lists trade cache-friendly indexed access for flexible local node operations.