Colors: Yellow = Current step/element, Blue = Next step, Green = Completed, Red = Checked elements, Green element = Found
Linear Search is a simple searching algorithm that checks each element in an array sequentially until the target is found or the end is reached.
How it works:
Time Complexity: O(n) - worst case checks all elements
Scenario: A bank needs to find a customer's transaction record in an unsorted log file. Linear search sequentially checks each transaction until finding the matching record.
Input: Unsorted list of 10,000 transactions, searching for transaction ID 'TXN-5432'
Process: Check transaction 1, transaction 2, ... until target found at position 7,523
Output: Transaction record found with customer details, amount, and timestamp
Linear search is ideal for unsorted data because it requires no preprocessing and works on any data structure. Unlike binary search which requires sorted data, linear search handles random-order logs without modification. For small to medium datasets (up to thousands of elements), the O(n) performance is acceptable and the implementation is straightforward. It's perfect for searching through event logs, transaction records, or any sequential data where sorting isn't feasible.
Benefits: No sorting required, works on any data structure, simple implementation, suitable for small datasets, finds first occurrence naturally