Back to Blogs
created 23 days ago

Searching Algorithms Explained – Linear Search & Binary Search (O Level Computer Science 2210 / 0478)

What Is a Searching Algorithm?

A searching algorithm is a method used to locate a specific value within a list or array of data.

Searching is very important in computing because programs often need to find:

  • A student’s record in a database

  • A product in an online store

  • A file in a computer system

Efficient searching algorithms help computers find data quickly and accurately.


Linear Search

Linear search is the simplest searching method.

It checks each element in the list one by one until the target value is found.

How Linear Search Works

1️⃣ Start at the first element in the list
2️⃣ Compare it with the target value
3️⃣ If it matches, the search stops
4️⃣ If not, move to the next element
5️⃣ Repeat until the value is found or the list ends


Example

Array:

[12, 25, 8, 30, 17]

Searching for 8:

  • Compare with 12 → Not match

  • Compare with 25 → Not match

  • Compare with 8 → Match found


Pseudocode Example

FOR i ← 1 TO 5
    IF numbers[i] = target THEN
        OUTPUT "Found"
    END IF
NEXT i

Advantages of Linear Search

  • Simple to implement

  • Works on unsorted lists

Disadvantages

  • Slow for large datasets

  • Must check many elements


Binary Search

Binary search is a more efficient searching algorithm used on sorted lists.

It works by repeatedly dividing the search range in half.


How Binary Search Works

1️⃣ Find the middle element of the list

2️⃣ Compare it with the target value

3️⃣ If it matches, the search ends

4️⃣ If the target is smaller, search the left half

5️⃣ If the target is larger, search the right half

This process continues until the value is found.


Example

Sorted array:

[5, 10, 15, 20, 25, 30]

Searching for 20:

  • Middle value → 15

  • Target > 15 → Search right half

  • Next middle → 25

  • Target < 25 → Search left half

  • Result → 20 found


Advantages of Binary Search

  • Much faster for large datasets

  • Reduces number of comparisons

Disadvantages

  • Works only on sorted data


Linear Search vs Binary Search

FeatureLinear SearchBinary SearchData order requiredNoYesSpeedSlowerFasterMethodCheck each itemDivide list in half

Binary search is generally more efficient when working with large sorted datasets.


Why Searching Algorithms Are Important

Searching algorithms are used in many real-world applications, such as:

  • Database systems

  • Search engines

  • File systems

  • E-commerce platforms

Efficient searching helps programs retrieve information quickly.


Exam Tip (2210 / 0478)

Students are commonly asked to:

  • Define linear search

  • Define binary search

  • Compare the two algorithms

A common exam question is:

Explain why binary search is faster than linear search.


Practice Question

Explain one disadvantage of binary search.

Answer

Binary search requires the data to be sorted before the search can be performed.


Study Computer Science with IVY Online

Preparing for Cambridge O Level Computer Science (2210) or IGCSE Computer Science (0478) requires strong programming skills and exam-focused practice.

With the IVY Online App, students can access:

  • Complete syllabus coverage

  • Interactive concept explanations

  • Programming practice

  • Past paper solutions

📱 Download the IVY Online App and start preparing smarter for Computer Science exams.