Cost with Two Independently Varying Input Sizes
When two inputs can grow independently, keep both sizes in the bound so it remains useful for unbalanced cases.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Count a simple join
Checking every record in one collection against the other uses \(nm\) pair comparisons. At \(n=3,m=100\) it checks 300 pairs. A hash-based join in memory can process both collections without checking all pairs under suitable hashing assumptions.
Remember output size
If every key matches every other key, returning all pairs can itself require \(nm\) records. A cost model must count that materialized result. Asymptotic input models explain analogous cases for varying graph size and edge count.[1]
Hold one dimension fixed while increasing the other
Scanning every effect of \(n\) newly submitted items across \(m\) rules can require \(nm\) checks. With \(m=2\) fixed this behaves linearly in \(n\). When both sizes double, the check count quadruples. Either observation can be true on its chosen workload. See input cost models.
(n, m) checks
(20, 2) 40
(40, 2) 80
(40, 4) 160
Include work that survives an empty dimension
Creating a report row for every item can take linear work in \(n\) even with no rules. Counting \(nm\) alone would predict zero. State whether setup, reporting and validation add terms, and test the empty cases separately.