Linear Search in Java

Here you will learn about linear search in Java.

It is one of the simplest and basic searching algorithm which is also known as sequential search.

The targeted element is compared with each element of array until it is found. Its best and worst case time complexity is O (1) and O (n) respectively.

Also Read: Binary Search in Java

Below program shows that how to implement this algorithm in Java.

Program for Linear Search in Java

 

Output

Enter size of array:
5

Enter array elements:
5 7 12 8 4

Enter element to search:
8

Element found at postion 4

2 comments

  • abhishek

    I am new to programing can u plz tell me why u have used string…s in main method instead of string[] args…what does it mean??

    Reply
    • Admin

      You can also use String…s instead of String args[]. Actually this feature was added in java 1.5. Both of them do the same work.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.