Searching Algorithms
Learn more about Searching Algorithms in DSA Self Paced Course
Practice Problems on Searching Algorithms
Top Quizzes on Searching Algorithms
What is Searching Algorithm?
Searching Algorithms are designed to check for an element or retrieve an element from any data structure where it is stored.
Based on the type of search operation, these algorithms are generally classified into two categories:
- Sequential Search: In this, the list or array is traversed sequentially and every element is checked. For example: Linear Search.
Linear Search to find the element “20” in a given list of numbers
Linear-Search
- Interval Search: These algorithms are specifically designed for searching in sorted data-structures. These type of searching algorithms are much more efficient than Linear Search as they repeatedly target the center of the search structure and divide the search space in half. For Example: Binary Search.
Binary Search to find the element “23” in a given list of numbers
Topic :
- Linear Search
- Sentinel Linear Search
- Binary Search
- Meta Binary Search | One-Sided Binary Search
- Ternary Search
- Jump Search
- Interpolation Search
- Exponential Search
- Fibonacci Search
- The Ubiquitous Binary Search
- Linear Search vs Binary Search
- Interpolation search vs Binary search
- Why is Binary Search preferred over Ternary Search?
- Is Sentinel Linear Search better than normal Linear Search?
Library Implementations of Searching Algorithms :
- Binary Search functions in C++ STL (binary_search, lower_bound and upper_bound)
- Arrays.binarySearch() in Java with examples | Set 1
- Arrays.binarySearch() in Java with examples | Set 2 (Search in subarray)
- Collections.binarySearch() in Java with Examples
Some standard problems on Searching:
- Easy:
- Find the largest three elements in an array
- Find the Missing Number
- Find the first repeating element in an array of integers
- Find the missing and repeating number
- Search, insert and delete in a sorted array
- Count 1’s in a sorted binary array
- Two elements whose sum is closest to zero
- Find a pair with the given difference
- k largest(or smallest) elements in an array
- Kth smallest element in a row-wise and column-wise sorted 2D array
- Find common elements in three sorted arrays
- Ceiling in a sorted array
- Floor in a Sorted Array
- Find the maximum element in an array which is first increasing and then decreasing
- Given an array of of size n and a number k, find all elements that appear more than n/k times
- Medium:
- Find all triplets with zero sum
- Find the element before which all the elements are smaller than it, and after which all are greater
- Find the largest pair sum in an unsorted array
- K’th Smallest/Largest Element in Unsorted Array
- Search an element in a sorted and rotated array
- Find the minimum element in a sorted and rotated array
- Find a peak element
- Maximum and minimum of an array using minimum number of comparisons
- Find a Fixed Point in a given array
- Find the k most frequent words from a file
- Find k closest elements to a given value
- Given a sorted array and a number x, find the pair in array whose sum is closest to x
- Find the closest pair from two sorted arrays
- Find three closest elements from given three sorted arrays
- Binary Search for Rational Numbers without using floating point arithmetic
- Hard:
- Median of two sorted arrays
- Median of two sorted arrays of different sizes
- Search in an almost sorted array
- Find position of an element in a sorted array of infinite numbers
- Given a sorted and rotated array, find if there is a pair with a given sum
- K’th Smallest/Largest Element in Unsorted Array | Worst case Linear Time
- K’th largest element in a stream
- Best First Search (Informed Search)
Recomended:
If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or if you want to share more information about the topic discussed above.