‼️Doubly Linked List

What is a Doubly Linked List?

circle-check

Just as the next property of a doubly linked list’s tail points to the null value, so too does the prev property of a doubly linked lists’s head.

Doubly Linked List

Key Characteristics:

  • Dynamic size: Nodes can be added or removed as needed.

  • Efficient insertion/deletion: Can be done at any position in O(1)O(1) time (average case), as you only need to update a few pointers.

  • Forward and backward traversal: You can move through the list in either direction.

  • No random access: Still requires traversal to access specific elements.

Big O Notation of Doubly Linked List Operations

Operation
Time Complexity
Explanation

Insertion (head/tail)

O(1)O(1)

Updating a few pointers.

Insertion (middle)

O(1)O(1) (average)

Assuming you know the insertion point, it's constant time.

Deletion (head/tail)

O(1)O(1)

Updating a few pointers.

Deletion (middle)

O(1)O(1)

Updating pointers of the node and its neighbors.

Search

O(n)O(n)

Still requires checking each node.

Access by index

O(n)O(n)

Traversal is needed for access.

Traversal (forward/backward)

O(n)O(n)

Visiting each node takes time proportional to the list's length.

Implementation of Doubly Linked List In JavaScript

Last updated