1.

Describe the Linear Search Algorithm.

Answer»

To find an element in a group of ELEMENTS, the linear search can be used. It works by traversing the list of elements from the beginning to the end and inspecting the properties of all the elements encountered along the way. Let us consider the case of an array containing some integer elements. We want to find out and print all of the elements' positions that match a particular value (also known as the "key" for the linear search). The linear search works in a flow here, matching each element with the number from the beginning to the end of the list, and then printing the element's location if the element at that position is equal to the key. 

Given below is an algorithm describing Linear Search:

  • Step 1: Using a loop, traverse the list of elements given.
  • Step 2: In each iteration, compare the target value (or key-value) to the list's current value.
  • Step 3: If the values match, print the array's current index.
  • Step 4: Move on to the NEXT array element if the values do not match.
  • Step 5: Repeat Steps 1 to 4 till the end of the list of elements is reached.

The time complexity of the Linear Search Algorithm is O(N) where n is the size of the list of elements and its space complexity is constant, that is, O(1). 



Discussion

No Comment Found