Functional Pearl 1 – The Min Missing Natural Number
typeocaml.com
typeocaml.com
I really hate it when people do that. This looks good in print, but the print is different medium with different constraints. Web is not print.
>But we can skip out ideally half of the numbers.
ideally, but in the worst case it's O(n * (n - 1)), or O (n^2)if your first X is the max, and your second choice is X-1, and so forth (in the worst case), then you're not operating in O(n), but n^2
I suppose answering with the average performance is useful if the routine is going to run a lot, but you'd better be careful even with that ... if the worst case is orders of magnitude bigger than the average, it may still matter.