Searching is one of the most common tasks computers do—from finding a contact in your phone to Googling a webpage. Understanding how searching works is the first step into the world of algorithmic efficiency.
An algorithm is simply a set of rules. A 'Search Algorithm' is a rule for finding a specific item. 'Linear Search' checks every item one by one. 'Binary Search' splits sorted data in half repeatedly, making it much faster for large amounts of data.
Simple but slow. Checks element 0, then 1, then 2, until it finds the target. Works on unsorted data.
Fast but requires sorted data. Checks the middle, eliminates half the data, and repeats.
If you have 1 million items, Linear Search might take 1 million steps. Binary Search takes at most 20 steps!
The biggest pitfall for beginners is trying to use Binary Search on an unsorted array. Binary search completely relies on the fact that the data is strictly ordered (e.g., smallest to largest). If it's not, the algorithm will confidently give you the wrong answer!
Select an algorithm and watch how many steps it takes the robot to find the target number!
Test your algorithm knowledge!
In computer science, we use 'Big O notation' to describe efficiency. Linear Search is O(n), meaning the time it takes grows linearly with the number of items (n). Binary Search is O(log n), meaning it grows logarithmically—making it exceptionally powerful for massive databases like Google's search index.