Skip to main content

Linear Search

Linear Search is a method of searching an element in a list. It is the simplest searching algorithm in which the element is searched in a sequential manner. Each element of the data structure is compared with the key(element to be searched) in a sequential order until the element is found or the last index is visited.

Illustration:


Algorithm:

LinearSearch(list,key)
    for each_item in list
        if(item==key)
            return item_index
    return -1

Linear Search Time Complexity:
  • Best Case : O(1)
  • Average Case : O(n)
  • Worst Case : O(n)
Space complexity: O(1)

Program for Linear Search


Popular posts from this blog

Coding Problem: Area of Circle

 Write a program to print the area of a circle of given radius ' r ' up to 2 decimal places. Code: Output:

Cosmic Techie

Most fascinating SuperPower is to play with Matter and Energy. It is the power to have possession over the Cosmos. To fulfil this desire, programmer play with code and hardware.