Time complexity
Time complexity describes how the number of operations grows as the input grows. It does not predict an exact duration because hardware, language, implementation details, and constant factors also affect runtime.
Use the growth patterns from Big O notation to inspect one help desk operation at a time. Looking up a report, assigning routine work, and traversing related reports are different algorithms.
Common patterns
| Pattern | Meaning | Example |
|---|---|---|
O(1) | The work stays approximately constant | Read a known array index |
O(log n) | Each step removes a large part of the remaining work | Binary search in sorted data |
O(n) | The work grows with the number of items | Scan a collection |
O(n log n) | A common cost for efficient comparison sorting | Sort a collection |
O(n^2) | Items may be compared with many other items | Compare every pair |
Reading code
A single loop over n items is often O(n). A loop inside another loop may be O(n^2), although the exact result depends on what each loop does. Sequential loops are usually added, and the dominant growth is kept when simplifying the result.
Not every nested loop is automatically a problem. The input may be small, or the inner loop may operate on a fixed-size collection. Complexity should guide investigation rather than replace it.
For example, a scan through the report log is O(n), a hash-based ID lookup is usually average O(1), and a graph traversal with V reports and E relationships is O(V + E). These are useful expectations, not measurements of one particular machine.
Use a growth label to describe the operation, not to justify a design change by itself.