3 ms·
As an aside: can you have an O(0) operation that actually does anything?
by arethuza 2y ago
As an aside: can you have an O(0) operation that actually does anything?
- mort96 2y agoIt doesn't really make sense within the context of complexity analysis as something distinct from constant-time, which is denoted with O(1). A copy of a CoW string is O(1).
- carapace 2y agoStuff that happens at compile-time is O(0) (well, technically it's amortized over the number of times you run the compiled code, eh? Huh, how does JIT compilation affect Big-O analysis?)
- dhosek 2y agoThis. Pretty much with complexity analysis, you factor out any constants and only look at the term of complexity with the highest growth rate, so you end up with 1 < ln n < n < nª < 2^n (this can be extended indefinitely by replacing the n in the last case with anything to the right of n, but in practice, these are the only ones that matter.
- mikewarot 2y agoIt copies the pointer to the data and increments the reference count. When you modify a string it checks the count and copies it prior to modification if it's not 1.
- Sohcahtoa82 2y agoO(0) is essentially meaningless. The only way a task could possibly be O(0) is if it isn't done at all, as even if the task is guaranteed to run in a Planck second [0], that's still constant time and would be O(1). [0] https://simple.wikipedia.org/wiki/Planck_time https://simple.wikipedia.org/wiki/Planck_time
- calfuris 2y agoOnly if you have an operation that actually does something in precisely 0 time.