Singly Linked List Deletion

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 can simply be 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

We will look at the implementation of the deletion at head algorithm.

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:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy