Data structure

Searching

Searching

In-memory data is structured in many ways and different places. For searching the data for use, we must apply some method. Searching algorithms are designed to retrieve an element from the data structure where it is stored so that users can easily access and modify it. In different data structures such as Linked List, Stack, Array, Queue, Graphs, an efficient algorithm is used for the retrieval of data from the memory.

What is searching: The process of finding the items from the memory is called searching in the data structure. Searching of the element is done by implementing the searching algorithm to retrieve the element from the stored data structure. There are specifically two types of algorithms;

  1. Sequential Search: In a sequential search, every element is traversed sequentially by checking each component.

Example. Linear search

  1. Interval search: In Interval searching, algorithms are applied to the sorted data structures. It is better than the sequential search because time complexity is low in these algorithms. 

Example. Binary Search

Linear search: In the Linear Search algorithm, elements are searched sequentially. In the best case time complexity is constant i.e. O(1) and in the worst-case time complexity is linear i.e. O(n) where n is the total number of elements in the list. It is the simplest algorithm and each item is checked until it matches the searched element.

Example: Let’s assume an array and its elements are in such way;

  24, 89, 45, 60, 34, 76, 90

Searching element: 90

In the above example, for searching 90 the algorithm will work 7 times so its time complexity is O(n) and here n=9.