What is Searching ?Why do we need Searching? Explain different Types of Searching ?

By | July 18, 2020

In this post, We will learn What is searching and what are the different types of searching algorithms we have in the data structure.

What is Searching?

In computer science, searching is the process of finding an item with the specified properties from a collection of items. The items may be stored as records in a database or a simple data element in the array, text in files, nodes in trees, vertices, and edges in graphs or they may be elements of other search spaces.

Why do we need searching?

Searching is one of the computer science algorithms. You know that today’s modern computers store a lot of information. To read this information proficiently, we need very efficient searching algorithms.

There are certain ways of organizing data that improves the searching process. That means If we keep the data in proper order it is easy to search the required elements. Sorting is one of the techniques for making the elements order. In this post, we will see different searching algorithms.

Types of Searching

The following are the types of searching available in computer science.

Unordered Linear Search

Let us assume, we have given an array where the order of the elements is not known. That concludes the elements of the array are not sorted. In this case, to search for an element, we have to scan the complete array and see if the element is there in the given array or not.

Sorted/Ordered Linear Search

If the elements of the array are already sorted then in most cases, we don’t really have to scan the complete array to see if the element is there in the given array or not. In the algorithm below, It can be seen that at any point if the value at intputArr[i] is greater than data to be searched then we just return -1  without searching the remaining array.

The time complexity of this algorithm is O(n).  This is because it is the worst. We need to scan the complete array but in the average case, it reduces the complexity even though the growth rate is the same.  Space complexity:O(1) 

Binary Search

Binary search is one of the search techniques. Which works efficiently on the sorted arrays or collection. Hence, in order to search an element in array or collection by using binary search techniques, we must ensure that the array or collection is sorted.

The binary search uses a divide and conquer algorithm in which, the arrays or collection is divided into two halves and the item is compared with the middle element of the collection. If the match is found for a given searching key then the location of the middle element is returned. Otherwise, we have to search into either of the halves depending upon the result produced through the match.

The complete implementation of Binary search is Here

Interpolation Search

Click Here to know more about Interpolation Seach

You May Also Like:

Java program for linear search using the Iterative Approach
Java program for linear search using Recursive Approach
Java program for Binary search using Iterative Approach
Java program for binary search using the Recursive Approach

That’s all about What is Searching? Why do we need Searching? Explain different types of Searching?
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *