Search and filtering in No-Code - Time & Space Complexity
When we search or filter through a list, we want to know how long it takes as the list grows.
We ask: How does the time to find or filter items change when the list gets bigger?
Analyze the time complexity of the following code snippet.
items = [1, 5, 8, 12, 20, 25]
result = []
for item in items:
if item > 10:
result.append(item)
This code goes through a list and keeps only the numbers greater than 10.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through each item in the list once.
- How many times: Exactly once for every item in the list.
As the list gets bigger, the time to check each item grows in a straight line.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: Doubling the list size doubles the work needed.
Time Complexity: O(n)
This means the time grows directly with the number of items you check.
[X] Wrong: "Filtering only a few items means the code runs quickly no matter the list size."
[OK] Correct: Even if few items match, the code still looks at every item once, so time depends on the whole list size.
Understanding how search and filtering time grows helps you explain your code choices clearly and confidently.
"What if the list was sorted and you stopped checking once items were too small? How would the time complexity change?"