
An algorithm is a clear set of steps for solving a problem. A recipe is an everyday example: follow the steps in order to make a meal.
Imagine looking for a friend’s name in a list of 100 names.
If the list is not sorted, you may check names one by one. In the worst case, you look at all 100. If the list grows to 1,000 names, the work can grow close to ten times as much. This is called linear growth, written as O(n).
If the names are sorted, you can open the list in the middle. If your name comes earlier, ignore the second half. Repeat with the remaining half. This is binary search. Its work grows much more slowly, written as O(log n).
Big O describes how an algorithm’s work grows as the input grows. It does not promise the exact number of seconds. The device, programming language, and data also affect real speed.
Example: for 8 names, checking one by one may take up to 8 checks. Binary search needs only a few checks, but it needs the list to be sorted first.
When comparing algorithms, ask how much work they do for small and large inputs, and what extra conditions they need. That is more useful than choosing one only because its code looks shorter.