Grokking Data Structures & Algorithms for Coding Interviews

0% completed

Operations on Singly Linked List

A linked list supports several fundamental operations that allow modification and traversal of elements efficiently. In this lesson, we will explore and implement the following operations:

  • Traversal (Visiting each node sequentially)
  • Insertion (Adding a node at the beginning, end, or middle)
  • Deletion (Removing a node from the beginning, end, or middle)

Each operation modifies the structure of the linked list by updating pointers and maintaining connectivity.

.....

.....

.....

Like the course? Get enrolled and start learning!
K

k.kromer

· 2 years ago

After a Given Node - O(n): Traverse the list to the desired node and insert the new node after it.

As reflected in the code example, the time complexity for this operation is O(1) since you don't need to traverse the list. You set the next reference of the provided node to the newly created node which in turn points the previous next.

Niladri Roy

Niladri Roy

· a year ago

Java implementation of LinkedList has a tail pointer, making tail operations O(1) instead of O(n).