What is a linked list?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Data Structures & Algorithms development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
A linked list is a linear data structure where elements (nodes) are stored in non-contiguous memory. Each node contains data and a pointer (reference) to the next node. Types: Singly linked list: each node points to the next; traversal is one-directional; Doubly linked list: each node has pointers to both next and previous nodes; enables bidirectional traversal, O(1) deletion given a node reference; Circular linked list: the last node points back to the first. Operations: Access by index: O(n) (must traverse from head); Search: O(n); Insert at head: O(1); Insert at tail: O(1) with tail pointer; Insert at middle: O(n) to find position, then O(1) for pointer manipulation; Delete: O(n) to find, O(1) to delete (given the node or previous node). Pros: dynamic size, O(1) insert/delete at head/tail, efficient for frequent insertions/deletions. Cons: no random access (O(n) to reach index n), extra memory per node for pointers, poor cache performance (non-contiguous). Real use: LRU cache (doubly linked list + hash map), undo/redo in editors, browser history, adjacency lists in graphs.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Data Structures & Algorithms answers easy to follow.