DSA – Introduction
How to Delete an Element at a Particular Index in a
Introduction to Data
Structure given Array
Physical vs Logical Data
Structure Back to: Data Structures and Algorithms Tutorials
Stack vs Heap Memory
Abstract Data Type (ADT)
How to Delete an Element at a Particular Index in a given Array
Time and Space
Complexity
in C:
What is Algorithm
Analysis of Algorithm
In this article, I am going to discuss Deletion in an Array i.e. how to delete an element at a particular index in a
Big-O Notation given array using both C and C++ Language with Examples. Please read our previous article, where we
Properties of Asymptotic discussed How to Display Append and Insert Elements in an Array.
Notations
Master Theorem Understanding the Concept i.e. Deletion in an Array:
Recursion And
BackTracking Here, we will learn how to delete or remove a particular element from an array using both C and C++
Programming Languages. An array is a collection of elements of the same data type stored in a contiguous
Essential Concepts of C and memory location. In C programming language, an array is derived data that stores primitive data type values like
C++ Programming int, char, float, etc. To delete a specific element from an array, we must define the position from which the array’s
Arrays element should be removed. The deletion of the element does not affect the size of an array. Furthermore, we
should also check whether the deletion is possible or not in an array.
Structure
Pointers
For example, suppose an array contains 8 elements, arr[] = {10, 25, 14, 8, 12, 15, 5); and the user want to delete
References in C++
element 8. So, first, the user must define the position of the 8th element, which is the 4th, and then check whether
Pointer to Structure the deletion is possible or not. The position of the particular element should not be more than the total elements of
Functions an array. Here, we have 7 elements in an array, and the user wants to delete the 8th position element, which is
Parameter Passing impossible.
Methods
Array as Parameter Steps to Delete an Element at a Particular Index in a given Array
Structure as Parameter
Let’s create an array of size 10 and set the length of the array to 0 as there is no element inside our array.
Structures and Functions
Converting a C Program
to C++
Class and Constructor in
C++
Template Classes in C++
Environment Setup for
Programming
Setup Dev C++ and Now, we insert some elements in the above array. Here, we insert 6 elements, so the length of the array will also
Settings 6.
Code Blocks IDE Setup
and Settings
Recursion
How does Recursion
works in C and C++?
How Recursion Uses Stack
Time Complexity of
Recursive Function
Static and Global
Variables in Recursion
Tail Recursion
Head Recursion Now, I want to delete an element at a given index from the above array. Let’s take the example of Delete (4). In the
Tree Recursion above array, 6 is stored at the 4th index. So, we have to remove six. To perform the deletion, we have to follow the
below steps:
Indirect Recursion
Nested Recursion
1. First, store the element in another variable that you want to delete from the array. Int x = arr [4];
Sum of First N Natural 2. Second, when we delete an element from an array, those elements which are present after the element
Number in C which we have deleted, we have to right shift these elements by 1, so that there will no empty space inside
Factorial of a Number in C our array.
Power of a number Using
In the above array, as we have already stored that element in another variable, now we can proceed to shift. In the
Recursion in C
below image, we are shifting 9 from index 5 to 4.
Taylor Series Using
Recursion in C
Taylor Series Using
Horner’s Rule
Combination Formula
using Recursion in C
Fibonacci Series using
Recursion in C
Tower Of Hanoi using
Recursion in C
Then, we are shifting 10 from index 6 to 5.
Array – Representation
Array Declaration and
Initialization
Static vs Dynamic Array in
C/C++
How to increase the size
of an Array
2-D Arrays in C/C++
Array Representation by
Compiler
As we have shifted both the elements, we have to decrease the length by 1 because here we deleted one element
Array – ADT from the given array.
Array Abstract Data Type
Display Append and
Insert Elements in an
Array
How to Delete an
Element at a Particular
Index in a given Array
Linear Search in Array
Binary Search in C
Array Basic Operations in Now let’s see how we can do this in C language.
C
Array Reverse and Shift
Operations in C
Checking if Array is Sorted
in C
Merging Arrays in C
Array Set Operations in C
Menu Driven Program
using Array in C
How to Convert Array C
Code to C++ Code
Finding Single Missing
Element in an Array in C
In deletion operation, we know,
Finding Multiple Missing
Elements in an Array in C 1. The minimum shifting is 1 i.e. when we want to delete the last 2nd element
2. The maximum shifting Is n i.e. when we want to delete the first element of the array.
Finding Duplicates in a 3. The minimum time is constant and the maximum time is n to perform the deletion.
Sorted Array in C
Example to Delete an Element at a Particular Index in a given Array using C
Find Duplicate Elements
in an Array using Hashing
Language :
in C
#include <stdio.h>
Finding Duplicate #include <stdlib.h>
Elements in an Unsorted
Array in C struct Array {
int* A;
Finding a Pair of Element int size;
with Sum K from an int length;
Unsorted Array in C };
How to Find a Pair of
int Delete(struct Array* arr, int index) {
Element with Sum K in a
int x = 0;
Sorted Array
How to Find Maximum if (index >= 0 && index < arr->length) {
and Minimum Element in x = arr->A[index];
for (int i = index; i < arr->length - 1; i++)
a Single Scan
arr->A[i] = arr->A[i + 1];
arr->length--;
Matrices
return x;
Matrices Introduction }
Diagonal Matrix }
Lower Triangular Matrix
int main() {
by Row-Major Mapping
struct Array arr;
Lower Triangular Matrix
Column Major Mapping printf("Enter Size of an Array: ");
Upper Triangular Matrix scanf("%d", &arr.size);
Row Major Mapping
arr.A = (int*)malloc(sizeof(int) * arr.size);
Upper Triangular Matrix arr.length = 0;
Column Major Mapping
Symmetric Matrix printf("Enter Number of Elements: ");
scanf("%d", &arr.length);
TriDiagonal and TriBand
Matrix printf("Enter All Elements: \n");
Toeplitz Matrix for (int i = 0; i < arr.length; i++) {
Menu Driven Program for scanf("%d", &arr.A[i]);
Matrices
}
Sparse Matrix Data printf("\nDeleted Element is : %d\n", Delete(&arr, 4));
Structure
Addition of Sparse getchar();
Matrices }
Array Representation of Output:
Sparse Matrix
Polynomial in C
Linked List Data Structure
Why Linked List Data
Structure
What is Linked List Data
Structure
How to Display a Linked
List in C
Recursive Function for
Displaying a Linked List in
C
How to Count Nodes in a Example to Delete an Element at a Particular Index in a given Array using C++
Linked List
Language :
Sum of all Elements in a
Linked List #include <iostream>
Maximum Element in a #include <conio.h>
using namespace std;
Linked List