{
  "id": 9148527,
  "title": "Big-O explained simply",
  "url": "https://urgent.news/2026/09/22/big-o-explained-simply",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-22T14:07:18.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/ljgeorgiou/big-o-explained-simply-4888"
  },
  "original_language": "en",
  "account": "Big-O notation is a tool used to describe the efficiency of a program, specifically how the amount of work increases as the input size grows. To illustrate, consider three examples of functions that process lists of items.\n\nThe first example, `first(items: list[Any]) -> Any`, returns the first item in a list regardless of its length, performing only one step. This function has a Big-O of O(1) or constant time, since the work doesn't change with the size of the list.\n\nThe second example, `count(items: list[Any]) -> int`, computes the number of items in the list by iterating through each one and incrementing a counter. As the list grows, the number of steps increases linearly with the input size, resulting in a Big-O of O(n), or linear time.\n\nThe third example demonstrates a more efficient search technique. Given a sorted phonebook, we can locate a name by repeatedly dividing the remaining portion of the list in half, similar to how binary search works. This halving process yields a Big-O of O(log n), where the work grows very slowly as the input size increases. For instance, a phonebook of a billion names would only require about 30 steps to find a name using this method.\n\nWhen comparing these three scenarios, it becomes apparent that Big-O notation has practical implications in real-world programming. Let's examine two versions of a function that checks for duplicates within a list. The first version, `has_duplicates_v1(items: list[Any]) -> bool`, employs a list, `already_seen`, to keep track of previously encountered elements. It checks if an item exists in this list by scanning the entire `already_seen` list, resulting in an O(n²) Big-O complexity.\n\nThe second version, `has_duplicates_v2(items: list[Any]) -> bool`, utilizes a set, `already_seen`, to store the encountered elements. The key advantage of using a set is that checking for the presence of an item is an O(1) constant-time operation. Consequently, the Big-O of this version is O(n), which is significantly more efficient than the list-based approach. In fact, when tested on a list of 20,000 items, the set-based function completed in approximately 0.001 seconds, while the list-based version took around 1.1 seconds - a thousand times faster.\n\nIn summary, understanding Big-O notation can help developers optimize their code and improve its performance, especially when dealing with larger datasets. Choosing the appropriate data structures, such as switching from a list to a set, can make a substantial difference in the efficiency of a program.",
  "summary": "When I first heard about Big-O it sounded intimidating, but it turned out to be a simple idea once I saw a few examples. Here's how it finally clicked for me. What does Big-O measure? Big-O is used to describe the efficiency of a program, specifically, how the amount of work grows as the input gets bigger. Let's look at an example: def first ( items : list [ Any ]) -> Any : return items [ 0 ]…",
  "key_points": [
    "Big-O notation describes program efficiency and input size growth",
    "First example has O(1) constant time complexity",
    "Third example achieves O(log n) logarithmic time complexity"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}