## Searching in Data structure: Different types of search methods

The number of internet users are increasing and so are the communication networks. The number of data generated on the internet is rising with each passing day, so the datasets are becoming complex. It is very important to manage , organise , analyse and access the data efficiently and carefully. For doing all this, Data structure is a very crucial technique.

In this article we would know about the data structure and the types of searching in data structure.

In computer programming, data structures are the basics for ADT (Abstract data types), where ADT are the logical form of the data type. Different data structures are used for different types of applications and tasks.

Basically the Data Structure is the collection of data and the relationships between them. A data structure assists to store, manage, and organise a particular data format. We can do different operations and functions among the elements of a data structure.

Using data structures algorithms, you can manage and apply operations on large numbers of data, like massive databases. Apart from storage of data, data structure algorithms are also responsible for retrieving information from memory. Different types of Data Structures are Linked List, Searching, Sorting, Stack, Pointer, Queue, Graph, Programs, Structures , and so on.

**What are types of searching in data structure**

Searching in data structure is the process of finding the desired data or item from the set of data stored in the memory of a computer. These sets of data are stored in the computer memory in various forms which includes array, graph, tree or linked list.

Searching in Data Structure is also defined as locating the element from the collection of items.

**Types of searching methods: **

By implementing different search algorithms to check or retrieve an element , you can do searching in data structure. Basically it is the process of searching out the desired element from a set of stored elements in data structure from different search operations.

**Searching methods:**

**Sequential Search:**

In sequential search, the list of elements are traversed in a sequential manner while checking every element of the set.

For example, Linear Search.

**Interval search**

Interval search algorithms are used for searching in sorted data structures. Interval searches are more efficient than linear search.

Example: Logarithmic Search, Binary Search

These methods are examined based on the time taken by an algorithm to search an element matching the search item in the data collections and are given by,

These search methods are examined by the time taken by an algorithm to search for the desired element and are given by:

The best possible time

The average time

The worst-case time

Worst case time is the primary concern that leads to the guaranteed predictions of the performance of the algorithm. They are very easy to calculate as compared to the average time and the best possible time.

Let’s learn something more about the linear search and binary search:

Linear search

In a linear search algorithm, all the elements of a list or array are searched sequentially. The best execution time in linear search is 1 and the worst execution time is n. (n = total number of elements in the list)

Linear search algorithm is the simplest form of search algorithm in data structure. In this method, all the elements in the set of elements are checked to the end. Linear search algorithm is preferred for an unsorted data list.

**Complexities in Linear Search:**

**Space Complexity**

If n is the total number of elements in an array, then space complexity of a linear search is O(n). Linear search doesn’t use any extra space.

** **

**Time Complexity**

Best case complexity = O(1), when the desired element is present at the first element in the search list.

Worst case complexity = O(n) , when the search element is not present in the search list.

Average complexity = O(n), when the element is present somewhere in the search list.

**Binary Search**

Binary search algorithm finds the desired element by comparing the middlemost elements in the data collection. After finding the desired item, it returns to the index of the item. When the middlemost item is greater than the desired item, it starts searching to the left sub array of the middle item.

On the other hand, if the middlemost item is smaller than the desired item, it starts searching for the right sub array. The same process is repeated until the desired item is found or sub array size becomes zero.

Binary search algorithm applies for sorted order of items. It is more efficient than a linear search algorithm. Binary search algorithm works on the principle of divide and conquer.

**Complexities in Binary Search:**

(n is number of items present in the array)

Run-time complexity = O(log n)

Worst-case complexity = O (n log n)

Average complexity = O (n log n)

Best case complexity = O (1)