
10 Types of Programming Languages Every Coder should Know
Learn about different types of programming languages and how they are implemented in the real world.

In this article, we will learn about the linear search algorithm, also known as sequential search. This algorithm is widely used for straightforward implementation. It starts from one end and goes through each list element until the desired element is found; otherwise, the search continues until the end of the dataset.
Linear search is a computer science algorithm for finding elements in a collection. In a linear search algorithm, each collection element is visited sequentially to find the desired element. Linear search is also known as sequential search.

POSTGRADUATE PROGRAM IN
Multi Cloud Architecture & DevOps
Master cloud architecture, DevOps practices, and automation to build scalable, resilient systems.
This section will explain the Linear Search algorithm in proper working functionality.
Suppose a list of elements is given, and let’s say we want to find the 43 in the list of elements.
Data example : [33,44,99,33,43, 23,4,23]

A step-by-step explanation of the example is given below.
Step 1: We search the list’s first element, ‘33’. We must compare ‘33’ with the target value ‘43’. Since ‘33’ is not equal to ‘43’. So, we move to the next element in the list.
Step 2: Next, we examine the second element, ‘44’. We have to compare ‘44’ with ‘43’. Again, ‘44’ does not match ‘43’, so we continue to the third element.
Step 3: The third element in our list is ‘99. We will compare ‘99’ with ‘43’ and once more. They do not match. So, we proceed to the fourth element.
Step 4: The fourth element is ‘33’. We compare ‘33’ with ‘43’. As before, ‘33’ does not match ‘43’. So, we keep searching and move to the fifth element.
Step 5: We have reached the fifth element, ‘43’. We compare this element with our target value ‘43’. This time, we found a match. The value ‘43’ is indeed the element.
Step 6: We have found the target value and concluded our search. The linear search algorithm has successfully located the value ‘43’ at the index ‘4’ in the list.\
Also Read: Python Tutorial for Beginners
Let’s look at some use cases of linear search algorithms:
In this section, we will see the Python linear search algorithm in Python. For a better understanding. Let’s look at the algorithm followed by the following code:
Let’s dive deep into the programming part of the Linear Search in Python.
Example 1: The example below is for searching for the index of 6 in the given array if it is present.
def search(a, l, x):
for i in range(l):
if (a[i] == x):
return i
return -1
a = [33, 44,99,33,43,234,23]
print("The given array is ", a)
x = 43
print("Element to be searched is ", x)
l = len(a)
ind = search(a, l, x)
if(ind == -1):
print("Element Not Found")
else:
print("Element is at index ", ind)
Output
The given array is [33, 44, 99, 33, 43, 234, 23]
Element to be searched is 43
Element is at index 4
Example 2: The example below searches for the index 9 in the given array if it is present.
Program
def search(a, l, x):
for i in range(l):
if (a[i] == x):
return i
return -1
a = [12, 43, 34, 45, 23]
print("The given array is ", a)
x = 9
print("Element to be searched is ", x)
l = len(a)
ind = search(a, l, x)
if(ind == -1):
print("Element Not Found")
else:
print("Element is at index ", ind)
Output
The given array is [12, 43, 34, 45, 23]
Element to be searched is 9
Element Not Found
Example 3: This example searches the index of 2 in the given array if it is present.
Program
def search(a, l, x):
for i in range(l):
if (a[i] == x):
return i
return -1
a = [99, 34, 65, 43, 223]
print("The given array is ", a)
x = 43
print("Element to be searched is ", x)
l = len(a)
ind = search(a, l, x)
if(ind == -1):
print("Element Not Found")
else:
print("Element is at index ", ind)
Output
The given array is [99, 34, 65, 43, 223]
Element to be searched is 43
Element is at index 3

82.9%
of professionals don't believe their degree can help them get ahead at work.
Let’s see the time and space complexity of the linear search algorithm.
Time Complexity
Space Complexity
In this article, we learned that linear search in Python is a straightforward method for finding a target value within a list. This simplest algorithm suits small datasets or scenarios where the list is not sorted. However, its linear time complexity is O(n), which may not be the most efficient choice for large datasets compared to algorithms like binary search. Linear search remains a fundamental computer science concept and is a foundational example of basic searching techniques. Understanding the principle can pave the way for grasping more complex algorithms and data structures used in Programming and software development.
Updated on February 17, 2025

Learn about different types of programming languages and how they are implemented in the real world.

Explore 10 front-end development, including key languages, its advantages and disadvantages, and how it shapes user experience in web design and functionality.