What is Searching Algorithm? Linear or Sequential Algorithm [Fully Explained]

Searching Algorithm

What is the Searching Algorithm? 

These algorithms are designed to check or to retrieve an element from any Data Structure.

Why I am saying from any data structure because -- We can have Arrays. We can have a Linked list. We can have Trees, So out of those in any of the Data structures.

If I want to search for one particular element. suppose if I have a list of the element in an array and I want to search one element for that we can use this Searching algorithm or suppose if I have a linked list and I want to search an element in that case also I can use these algorithms.

So, These algorithms are designed to check or to retrieve an element from any data structure.

If I'm saying any Data structure that means your arrays, linked list, stacks, queues, trees, graphs any

 where it is stored

Okay, now it depends you are using which type of data structure. So from that data structure if I want to look for a particular element then I can take these searching algorithms based on the search type. These algorithms are classified into two categories.

Now how we are searching the things see we have different techniques to search an element from a list.

  •  Linear Search or Sequential Search.
  • Binary Search or Interval Search

what is a Linear Search?

In linear search. Array or List is traversed sequentially (traversing means we are visiting each element exactly once that is traversing)

If I'm saying I want to traverse my array or traverse my list that means I want to visit each element.

So in Linear search, Each array or list element is traversed sequentially which means one after another.

I cannot say I have visited the first element then I will go to 4th element .No

After first I need to take second and third and fourth and so on right and every element is checked till we found the desired element and we keep on checking our list till the element which we are looking we are not able to find out that is known as linear or sequential search.

In this search, We start from the very first element and we will keep on moving to the next element till our desired element is found.



Post a Comment

0 Comments