Deletion in a Singly Linked List

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

Introduction #

The deletion operation combines principles from both insertion and search. It uses the search functionality to find the value in the list.

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. Even then, the end of the array is empty and it takes up unnecessary memory.

In the case of linked lists, the node is removed merely in constant time.

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

Types of Deletion #

There are three basic delete operations for the linked list:

  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 following lessons.

Delete at the head #

This operation 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.