• Can be used to implement multiple ADTs, including Queue and List
  • Nodes
    • the front/back variables
    • Head node
      • The 1st node
    • Tail node
      • The last node
    • In memory
      • They are NOT stored contiguously in memory, instead each node has the address of its succeeding node
      • So when adding/deleting elements, its performance is much better than arraylists
      • Since each node contains the data and links (references), the more nodes the more memory usage
    • Nodes that are not referenced anymore (in dequeue) are cleaned up by Garbage collection (GC)
  • O(n) for traversal

In Java

LinkedList<Integer> list = new LinkedList<>(List.of(1,2,3));
  • Its possible to use list.get() to access an element, but its not recommended
    • Every find function you use for a LinkedList, you have to iterate through it

Types

  • singly linked list
    • [Data | Next] -> [Data | Next] -> [Data | Next] -> NULL
  • doubly linked list
    • NULL <- [Prev | Data | Next] <-> [Prev | Data | Next] -> NULL
    • used in ☕Java
FeatureSingly Linked ListDoubly Linked List
Node StructureEach node has data + a pointer to next nodeEach node has data + pointers to next & prev
Navigation DirectionOne direction (forward only)Two directions (forward and backward)
Memory UsageLess (only one pointer per node)More (two pointers per node)
Insertion at HeadO(1)O(1)
Insertion at TailO(n) without tail pointer, O(1) with itO(1) if tail pointer is maintained
Deletion at HeadO(1)O(1)
Deletion at TailO(n) (must traverse)O(1) if tail pointer is maintained
Deletion of Arbitrary NodeO(n), need previous nodeO(1), if node reference is given
Backward TraversalNot possiblePossible
Ease of ImplementationSimplerMore complex
Use CasesStack, simple list-based structuresDeques, undo-redo systems, complex navigation

Circular Array vs LinkedList

FeatureLinked ListCircular Array
Resizing ProcedureNo specific resizing procedureMore complex (requires resizing)
Space UsageBetter for a large queue - uses less spaceMore space (linked list uses 2 things to keep track of)
IndexingXEasy to do
Complexity of OperationsMore complex (resizing, modulus, etc.)