0% found this document useful (0 votes)
3 views

14. Data Structure and Algorithms Linear Search

Linear search is a straightforward algorithm that checks each item in a list sequentially until a match is found or the end of the list is reached. Its time complexity is O(1) for the best case, O(n) for average and worst cases, making it suitable for smaller lists. For larger lists, alternative algorithms like binary search are recommended for faster results.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

14. Data Structure and Algorithms Linear Search

Linear search is a straightforward algorithm that checks each item in a list sequentially until a match is found or the end of the list is reached. Its time complexity is O(1) for the best case, O(n) for average and worst cases, making it suitable for smaller lists. For larger lists, alternative algorithms like binary search are recommended for faster results.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Data Structure and

Algorithms Linear
Search
Linear search is a very simple search algorithm. In this type of search, a sequential search is
made over all items one by one. Every item is checked and if a match is found then that
particular item is returned, otherwise the search continues till the end of the data collection.

Linear Search ( Array A, Value x)


Step 1: Set i to 1
Step 2: if i > n then go to step 7
Step 3: if A[i] = x then go to step 6
Step 4: Set i to i + 1
Step 5: Go to Step 2
Step 6: Print Element x Found at index i and go to step 8
Step 7: Print element not found
Step 8: Exit
Linear Search Complexity
Time complexity of linear search algorithm -
 Base Case - O(1)
 Average Case - O(n)
 Worst Case -O(n)
Linear search algorithm is suitable for smaller list (<100) because it
check every element to get the desired number. Suppose there are
10,000 element list and desired element is available at the last position,
this will consume much time by comparing with each element of the list.
To get the fast result, we can use the binary search algorithm.
We have discussed the basic concept of the linear search. In the next
tutorial, we will learn the second and most popular searching algorithm
named Binary search.

You might also like