0% found this document useful (0 votes)
2 views4 pages

Linear Search

Linear search is a straightforward algorithm that checks each element in an array sequentially until it finds the target or exhausts the array. It has a best-case time complexity of O(1) and a worst-case of O(n), making it inefficient for large datasets compared to binary search. Real-world applications include Google Chrome's browsing history search, where it effectively handles small, unordered datasets without the need for sorting.

Uploaded by

leonhardkwahle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Linear Search

Linear search is a straightforward algorithm that checks each element in an array sequentially until it finds the target or exhausts the array. It has a best-case time complexity of O(1) and a worst-case of O(n), making it inefficient for large datasets compared to binary search. Real-world applications include Google Chrome's browsing history search, where it effectively handles small, unordered datasets without the need for sorting.

Uploaded by

leonhardkwahle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Linear search

Linear search is the simplest searching algorithm. It checks each element


in the array one by one until it finds the target or reaches the end of the
array.

Time Complexity:
 Best Case (O(1)) → If the target is the first element.
 Worst Case (O(n)) → If the target is at the end or not present.
 Average Case (O(n)) → On average, it checks half the elements.

Implementation in JavaScript
Pros & Cons
✅ Pros:
✔ Works on both sorted and unsorted arrays.
✔ Easy to implement.
✔ No extra space required (in-place search).

❌ Cons:
❌ Slow for large datasets.
❌ Not efficient compared to binary search for sorted data.

Real-World Use Case of Linear Search in a Named


Software
🔹 Example: Google Chrome’s Browsing History Search

Company: Google
Software: Google Chrome (Web Browser)

How Linear Search is Used?

When you search for a previously visited webpage in your browsing


history, Chrome stores history records in a list (usually a database or an
in-memory array for recent entries). If you search for a non-indexed
keyword, Chrome may use Linear Search to scan through a user’s recent
history.

Why Linear Search?

 Fast for small datasets (recent history is typically small).


 Works well for unordered data (history is stored by visit time, not keyword
order).
 No sorting required (unlike Binary Search, which needs sorted data).
Example Code (Simplified Version in JavaScript)

Why Not Binary Search?

 Binary Search requires sorted data (history is stored by visit time,


not sorted alphabetically).
 Adding new entries constantly changes the list, making sorting
inefficient.

Other Companies & Software That Use Linear Search


1. Spotify – Searching for songs in a recently played list.
2. Netflix – Finding a movie in "Continue Watching" (usually a short
list).
3. Microsoft Excel – Finding a specific cell value in an unsorted column.
If you want to go deeper
Optimized Version (Using for...of)

Searching in an Array of Objects

Searching in a 2D Array (Matrix)

Searching in a String (Finding a Character)

Recursive Linear Search

Optimized Linear Search Techniques

Source: chatGPT.

You might also like