VOOZH about

URL: https://www.geeksforgeeks.org/dsa/search-insert-and-delete-in-an-unsorted-array/

⇱ Search, Insert, and Delete in an Unsorted Array | Array Operations - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Search, Insert, and Delete in an Unsorted Array | Array Operations

Last Updated : 23 Jul, 2025

In this post, a program to search, insert, and delete operations in an unsorted array is discussed.

Search Operation:

In an unsorted array, the search operation can be performed by linear traversal from the first element to the last element. 

👁 Image

Coding implementation of the search operation:


Output
Element Found at Position: 5

Time Complexity: O(N) 
Auxiliary Space: O(1)

Insert Operation:

1. Insert at the end:

In an unsorted array, the insert operation is faster as compared to a sorted array because we don't have to care about the position at which the element is to be placed.

👁 Image

Coding implementation of inserting an element at the end:


Output
 Before Insertion: 12 16 20 40 50 70 
 After Insertion: 12 16 20 40 50 70 26 

Time Complexity: O(1) 
Auxiliary Space: O(1)

2. Insert at any position

Insert operation in an array at any position can be performed by shifting elements to the right, which are on the right side of the required position

👁 Image

Coding implementation of inserting an element at any position:


Output
Before insertion : 2 4 1 8 5 
After insertion : 2 4 10 1 8 5 

Time complexity: O(N)
Auxiliary Space: O(1)

Delete Operation:

In the delete operation, the element to be deleted is searched using the linear search, and then the delete operation is performed followed by shifting the elements. 

👁 Image


Output
Array before deletion
10 50 30 40 20 

Array after deletion
10 50 40 20 

Time Complexity: O(N) 
Auxiliary Space: O(1)


Comment
Article Tags:
Article Tags: