Skip to content

Array Deletions and Shifting Algorithms

Gopi Gorantala
Gopi Gorantala
2 min read

Table of Contents

Removing an array element is similar to Array insertions, but we remove an element with the following 3 different cases:

  1. Delete an element at the first index.
  2. Delete an element at the last index.
  3. Delete an element at any given index (say, middle).

Before reading this article about insertions and deletions, I recommend reading the following:

Introduction To Array Data Structure
This article will dive deep into arrays introduction, array initialization, strengths, and weakness with complexity analysis. You will also see sketches and snippets explaining in detail.
Array Insertions And Shifting Algorithms
This article details array capacity vs length and shifting algorithms to insert an element at the array’s start, middle, and end with complexity analysis.

You can skip reading these articles above if you already know an array's strengths, weaknesses, and array-shifting algorithms.

Array Deletions

Deleting an element at the start/middle of an array falls under array weaknesses, which might impact the performance if we are dealing with a massive array of elements as we need to shift the rest of the elements, which takes O(N) time unless we remove/delete an element at the end of the array, which takes O(1) time.

Note: If we are to just update the value at an index in the array, it takes O(1) time.

1. Delete from the end of the array

Data Structures and AlgorithmsJava

Gopi Gorantala Twitter

Gopi is a highly experienced Full Stack developer with a deep understanding of Java, Microservices, and React. He worked in India & Europe for startups, the EU government, and tech giants.

Comments


Related Posts

Members Public

What is Big-O Complexity Analysis

In this lesson, you will gain knowledge about algorithm complexity analysis and the various types of big-O complexity analysis.

Members Public

Understanding the Importance of Big-O Notation in Coding Interviews

In this lesson, we will introduce the concept of big-o notation, a mathematical tool used to measure algorithm efficiency.

Big O Notation - Running time complexities against the input with length n
Members Public

What Are Data Structures And Algorithms?

In this lesson, you will gain knowledge about the significance and correlation between data structures and algorithms.