Singly Linked List Deletion

After insertion and search, we'll be tackling the concept of deletion in a linked list.

Introduction #

The deletion operation is mostly based on search operation. It uses the search functionality to find the value in the list, and then just deletes it.

Deletion is one of the instances where linked lists are more efficient than arrays. In an array, you have to shift all the elements backward if one element is deleted. In the case of linked lists, the node is simply removed in constant time.

Let’s take a look at the different types of deletion operations we can perform in singly-linked lists.

Types of Deletion #

There are three basic delete operations for linked lists:

  1. Deletion at the head
  2. Deletion by value
  3. Deletion at the tail

In this lesson, we will look at the implementation of the deletion at the head algorithm. The rest will be covered in the upcoming lessons.

Delete at Head #

This operation simply deletes the first node from a list. If the list is empty, the function does nothing.

Here’s an illustration of how this type of deletion works:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.