![]() |
VOOZH | about |
In this post, we will look into search operation in an Array, i.e., how to search an element in an Array, such as:
In an unsorted array, the search operation can be performed by linear traversal from the first element to the last element, i.e. Linear Search
Coding implementation of the search operation:
Element Found at Position: 5
Time Complexity: O(N)
Auxiliary Space: O(1)
In a sorted array, the most trivial method for search operation is by using Linear Search.
👁 Search Operation in a sorted array
Below is the implementation of the above approach:
Element Found at Position: 6
Time Complexity: O(N)
Auxiliary Space: O(1)
In a sorted array, the search operation can be performed efficiently by using binary search.
👁 Search Operation in a sorted array
Below is the implementation of the above approach:
Index: 5
Time Complexity: O(log(n)) Using Binary Search
Auxiliary Space: O(log(n)) due to recursive calls, otherwise iterative version uses Auxiliary Space of O(1).
Fibonacci Search is a comparison-based technique that uses Fibonacci numbers to search an element in a sorted array.
Below is the implementation of the above approach:
Found at index: 11
Time Complexity: O(log(n)) Using Fibonacci Search
Auxiliary Space: O(1) Using Fibonacci Search