Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18
Searching Algorithm
Searching Algorithm is an algorithm made up of
a series of instructions that retrieves information stored within some data structure, or calculated in the search space of a problem domain. There are many sorting algorithms, such as:
Linear Search, Binary Search, Jump Search,
Interpolation Search, Exponential Search, Ternary Search Linear Search Linear Search is a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched. Algorithm: Step1: Start from the leftmost element of array and one by one compare x with each element of array. Step2: If x matches with an element, return the index. Step3: If x doesn’t match with any of elements, return -1 Binary Search Binary Search is the most popular Search algorithm. It is efficient and also one of the most commonly used techniques that is used to solve problems. Binary search use sorted array by repeatedly dividing the search interval in half. Algorithm: Step1: Compare x with the middle element. Step2: If x matches with middle element, we return the mid index. Step3: Else If x is greater than the mid element, search on right half. Step4: Else If x is smaller than the mid element. search on left half. Difference between linear and binary search • Linear Search • Binary Search 1. Data can be in any order. 1. Data should be in a sorted 2. Multidimensional array also order. can be used. 2. Only single dimensional 3.TimeComplexity:- array is used. O( n) 3. Time Complexity:- O(log n 4. Not an efficient method to be 2) used if there is a large list. 4. Efficient for large inputs also.