Operations of Linked List

A linked list is a dynamic linear data structure made up of nodes connected through pointers. Each node contains data and the address of the next node. Unlike arrays, linked lists allow easy insertion and deletion of elements without shifting data.

To manage and manipulate the nodes in a linked list, several operations are performed. These operations help us add, remove, search, display, and modify data efficiently.

The main operations performed on a linked list are:

  • Traversal
  • Insertion
  • Deletion
  • Searching
  • Updating
  • Reversing

1. Traversal Operation

Traversal means visiting each node of the linked list one by one from the beginning to the end. It is one of the most fundamental operations because many other operations depend on traversal.

During traversal, we start from the head node and continue moving through the next pointers until the last node is reached. Since linked list nodes are stored at different memory locations, traversal is necessary to access every element.

Traversal is mainly used for:

  • Displaying nodes
  • Counting elements
  • Processing data

Example

10 → 20 → 30 → 40 → NULL

Traversal Output:

10 20 30 40

Algorithm

TRAVERSE(head)

1. temp = head
2. While temp ≠ NULL
       Print temp.data
       temp = temp.next
3. Stop

2. Insertion Operation

Insertion means adding a new node into the linked list. One of the biggest advantages of linked lists is that insertion can be performed easily without shifting elements.

Insertion can be done:

  • At the beginning
  • At the end
  • At a specific position

A. Insertion at Beginning

In this operation, a new node is inserted before the first node of the list.

The new node becomes the first node, and the head pointer is updated to point to the new node.

Example

Before insertion:

20 → 30 → NULL

After inserting 10:

10 → 20 → 30 → NULL

Working Process

  1. Create a new node
  2. Store data in the node
  3. Point the new node to the current head
  4. Move head to the new node

Algorithm

INSERT_BEGIN(head, value)

1. Create new node
2. new.data = value
3. new.next = head
4. head = new

B. Insertion at End

This operation inserts a node after the last node of the list.

To perform this operation, the list is traversed until the last node is found. Then the last node is connected to the new node.

Example

Before insertion:

10 → 20 → NULL

After inserting 30:

10 → 20 → 30 → NULL

Working Process

  1. Create a new node
  2. Traverse to the last node
  3. Connect last node to new node
  4. Set new node next to NULL

Algorithm

INSERT_END(head, value)

1. Create new node
2. new.next = NULL
3. Traverse to last node
4. last.next = new

C. Insertion at Specific Position

In this method, a node is inserted at a desired location in the linked list.

The node before the desired position is located first. Then the pointers are adjusted carefully to insert the new node.

Example

Before insertion:

10 → 30 → 40 → NULL

Insert 20 at position 2:

10 → 20 → 30 → 40 → NULL

Working Process

  1. Move to desired position
  2. Create new node
  3. Adjust pointers
  4. Insert node

Algorithm

INSERT_POSITION(head, value, pos)

1. Move to position-1
2. Create new node
3. new.next = temp.next
4. temp.next = new

3. Deletion Operation

Deletion means removing a node from the linked list. In linked lists, deletion is easier than arrays because elements do not need to be shifted.

Deletion can be performed:

  • From the beginning
  • From the end
  • From a specific position

A. Deletion from Beginning

The first node of the linked list is removed.

The head pointer is updated to point to the second node.

Example

Before deletion:

10 → 20 → 30 → NULL

After deletion:

20 → 30 → NULL

Working Process

  1. Store current head
  2. Move head to next node
  3. Delete old first node

Algorithm

DELETE_BEGIN(head)

1. temp = head
2. head = head.next
3. Delete temp

B. Deletion from End

This operation removes the last node from the linked list.

The second-last node becomes the new last node.

Example

Before deletion:

10 → 20 → 30 → NULL

After deletion:

10 → 20 → NULL

Working Process

  1. Traverse to second-last node
  2. Remove last node
  3. Set next pointer to NULL

Algorithm

DELETE_END(head)

1. Move to second-last node
2. Delete last node
3. temp.next = NULL

C. Deletion of Specific Node

This operation removes a node with a particular value or position.

Example

Before deletion:

10 → 20 → 30 → 40 → NULL

Delete 30:

10 → 20 → 40 → NULL

Working Process

  1. Search target node
  2. Connect previous node to next node
  3. Remove target node

Algorithm

DELETE_NODE(head, key)

1. Search for key node
2. Change links
3. Delete target node

4. Searching Operation

Searching means finding whether a particular element exists in the linked list.

Since linked lists do not support direct indexing, each node must be checked sequentially until the desired element is found.

Example

10 → 20 → 30 → 40 → NULL

Search Key = 30

Result: Element Found

Working Process

  1. Start from head
  2. Compare each node
  3. Continue until element is found or NULL reached

Algorithm

SEARCH(head, key)

1. temp = head
2. While temp ≠ NULL
       If temp.data = key
            Return Found
       temp = temp.next
3. Return Not Found

5. Updating Operation

Updating means modifying the value stored in a node.

Only the data part changes; the structure of the linked list remains the same.

Example

Before update:

10 → 20 → 30 → NULL

Update 20 to 25:

10 → 25 → 30 → NULL

Working Process

  1. Search target node
  2. Replace old value with new value

Algorithm

UPDATE(head, oldValue, newValue)

1. Search oldValue
2. Replace with newValue

6. Reversing Operation

Reversing changes the direction of the linked list.

After reversing:

  • The last node becomes the first node
  • The first node becomes the last node

This operation changes all pointer directions.

Example

Before reversing:

10 → 20 → 30 → NULL

After reversing:

30 → 20 → 10 → NULL

Working Process

  1. Reverse pointer direction
  2. Update head to last node

Algorithm

REVERSE(head)

1. prev = NULL
2. current = head
3. While current ≠ NULL
       next = current.next
       current.next = prev
       prev = current
       current = next
4. head = prev

Time Complexity of Linked List Operations

OperationTime Complexity
TraversalO(n)
Insertion at BeginningO(1)
Insertion at EndO(n)
Deletion at BeginningO(1)
SearchingO(n)
ReversingO(n)

Applications of Linked List Operations

Linked list operations are widely used in:

  • Music playlist systems
  • Browser history
  • Undo and redo operations
  • Memory management
  • Dynamic data storage
  • Graph implementation

Conclusion

Operations on linked lists are essential for dynamic data management. Traversal helps access nodes, insertion and deletion manage changes in the structure, searching locates required data, updating modifies node values, and reversing changes the order of the list. Because of these flexible operations, linked lists are widely used in operating systems, applications, and advanced data structures.

Previous Post
Linked List Data Structure
Next Post
Singly Linked List
0 people found this article helpful

Was this article helpful?