Bytes
rocket

Free Masterclass on Mar 21

Beginner AI Workshop: Build an AI Agent & Start Your AI Career

Searching Algorithms

Last Updated: 2nd February, 2026

Algorithms are step-by-step procedures or instructions to solve problems efficiently. In Python, implementing algorithms is much easier due to its simple syntax and powerful libraries. Algorithms can be broadly categorized into searching, sorting, and optimization techniques, among others.

tutorial 1 module 1 picture 1.png

Searching Algorithms

Searching Algorithms are techniques used to find the position or existence of a specific element within a collection of data such as an array, list, or database. They help in efficiently locating data without checking every element manually. Common searching algorithms include Linear Search and Binary Search, each with different performance and use cases.

Linear Search is the simplest searching technique where each element in a dataset is checked one by one until the target element is found. It works well on unsorted data, but can be inefficient for large datasets because it may need to examine every element. Its time complexity is O(n), where n is the number of elements.

In Python, linear search can be implemented using loops. The main operations performed in linear search are:

  • Search: Check each element sequentially to find the target.
  • Comparison: Compare the current element with the target.
  • Return: Stop and return the position/index once the target is found; otherwise, indicate it is not present.

Linear search is widely used in small datasets, unsorted collections, or when simplicity is preferred over efficiency.

Example

Input:

arr = [10, 25, 30, 45, 50]
x = 30

for i in range(len(arr)):
    if arr[i] == x:
        print("Element found at index:", i)
        break

Output:

Element found at index: 2

Binary Search is a more efficient searching technique that works on sorted arrays. It repeatedly divides the search space in half, comparing the target value with the middle element to determine whether to search the left or right half. This reduces the time complexity to O(log n), making it much faster than linear search for large datasets.

In Python, binary search can be implemented using loops or recursion. The main operations performed in binary search are:

  • Divide: Find the middle element of the current search space.
  • Compare: Check if the middle element matches the target.
  • Search: If the target is smaller, continue in the left half; if larger, continue in the right half.
  • Return: Stop and return the position once the target is found; otherwise, indicate it is not present.

Binary search is widely used in database lookups, dictionary searches, search engines, and any application involving large sorted datasets.

Example :

Input:

arr = [10, 20, 30, 40, 50]
x = 30
low, high = 0, len(arr) - 1

while low <= high:
    mid = (low + high) // 2
    if arr[mid] == x:
        print("Element found at index:", mid)
        break
    elif arr[mid] < x:
        low = mid + 1
    else:
        high = mid - 1

Output:

Element found at index: 2

Graphical Representation of Linear Search Algorithm

picture 2 module 1.png

Binary Search is a more efficient searching technique that works on sorted arrays. It repeatedly divides the search space in half, comparing the target value with the middle element to determine whether to search the left or right half. This reduces the time complexity to O(log n), making it much faster than linear search for large datasets.

In Python, binary search can be implemented using loops or recursion. The main operations performed in binary search are:

  • Divide: Find the middle element of the current search space.
  • Compare: Check if the middle element matches the target.
  • Search: If the target is smaller, continue in the left half; if larger, continue in the right half.
  • Return: Stop and return the position once the target is found; otherwise, indicate it is not present.

Binary search is widely used in database lookups, dictionary searches, search engines, and any application involving large sorted datasets.

Example :

Input:

arr = [10, 20, 30, 40, 50]
x = 30
low, high = 0, len(arr) - 1

while low <= high:
    mid = (low + high) // 2
    if arr[mid] == x:
        print("Element found at index:", mid)
        break
    elif arr[mid] < x:
        low = mid + 1
    else:
        high = mid - 1

Output:

Element found at index: 2
Module 3: Algorithms in PythonSearching Algorithms

Top Tutorials

Logo

Python

Python is a popular and versatile programming language used for a wide variety of tasks, including web development, data analysis, artificial intelligence, and more.

8 Modules37 Lessons59857 Learners
Start Learning
Logo

SQL

The SQL for Beginners Tutorial is a concise and easy-to-follow guide designed for individuals new to Structured Query Language (SQL). It covers the fundamentals of SQL, a powerful programming language used for managing relational databases. The tutorial introduces key concepts such as creating, retrieving, updating, and deleting data in a database using SQL queries.

9 Modules40 Lessons13986 Learners
Start Learning
Logo

Data Science

Learn Data Science for free with our data science tutorial. Explore essential skills, tools, and techniques to master Data Science and kickstart your career

8 Modules31 Lessons8792 Learners
Start Learning
  • Official Address
  • 4th floor, 133/2, Janardhan Towers, Residency Road, Bengaluru, Karnataka, 560025
  • Communication Address
  • Follow Us
  • facebookinstagramlinkedintwitteryoutubetelegram

© 2026 AlmaBetter