![]() |
VOOZH | about |
In this post, a program to search, insert, and delete operations in an unsorted array is discussed.
In an unsorted array, the search operation can be performed by linear traversal from the first element to the last element.
Element Found at Position: 5
Time Complexity: O(N)
Auxiliary Space: O(1)
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.
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)
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
👁 ImageBefore insertion : 2 4 1 8 5 After insertion : 2 4 10 1 8 5
Time complexity: O(N)
Auxiliary Space: O(1)
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.
Array before deletion 10 50 30 40 20 Array after deletion 10 50 40 20
Time Complexity: O(N)
Auxiliary Space: O(1)