Singly Linked Lists


Singly linked lists are a type of a linked list where each node points to the next node in the sequence. It does not have any pointer that points to the previous node. That means we can traverse the list only in forward direction,Unlike doubly linked list in which we can traverse in both direction using both pointers.

Operations on a singly linked list

Insert an item at the end of the linked list

1. Traverse through the linked list until the last node is reached.

2. Create a new node

3. Set the last node’s next pointer to the newly created node and next of newly added node to null.

Insert item after another item in linked list

1. Traverse through the linked list until the desired node A is found.

2. Create a new node using the data to be inserted.

3. Set the new node’s next pointer to the node A’s next pointer.

4. Set A’s next pointer to the newly created node.

Insert item at the head of the linked list

1. Create a new node

2. Set the new node’s next pointer to the head

3. Change the head pointer point to the newly added node.

Searching an item in the linked list

1. Start with the head and traverse till the null pointer

2. If the data matches, your data to be searched return true.

3. If the data does not match, go to the next node and repeat step 2.

Delete item at the head of the linked list

1. Make a new pointer pointing on head node.

2. Move the current head of the list to the second node.

3. Set the next pointer of the first node to null.

4. Delete the first node.

Delete item anywhere in the list

1. Search the list until you find the item you are looking for in the linked list .

2. Set K’s previous node’s next to the K’s next node’s next.

3. Set K’s next to null.

4. Delete K.

Delete item at the end

1. Traverse through the list until you get to the last node

2. Set the previous node’s next to null and delete the last node.

Complexities For Singly linked list

The complexities of the operations

Operation Complexity

Insert at the head O(1)

Insert at the end O(n)

Insert at the middle O(n)

Delete at the head O(1)

Delete at the end O(n)

Delete at the middle O(n)

Search the list O(n)


Happy Coding 😊

By Programmers Army

Contributed by: Parakh Pratap Singh