In this post search, insert and delete operation in an unsorted array is discussed.
[ad type=”banner”]
Search Operation
In an unsorted array, the search operation can be performed by linear traversal from the first element to the last element.
[ad type=”banner”]
C Programming
[ad type=”banner”]
Output:
Element Found at Position: 5
[ad type=”banner”]
Insert Operation
In an unsorted array, the insert operation is faster as compared to sorted array because we don’t have to care about the position at which the element is to be placed.
[ad type=”banner”]
C Programming
[ad type=”banner”]
Output:
Before Insertion: 12 16 20 40 50 70 After Insertion: 12 16 20 40 50 70 26
[ad type=”banner”]
Delete Operation
In delete operation, the element to be deleted is searched using the linear search and then delete operation is performed followed by shifting the elements.
[ad type=”banner”]
C Programming
[ad type=”banner”]
Output:
Array before deletion 10 50 30 40 20 Array after deletion 10 50 40 20
Time complexities:
Search: O(n)
Insert: O(1)
Delete: O(n)