search_ok("ooooooooooooooo", 15)
30 memory accesses. length times two. The article is correct. search_ok("ooooooooooooooo", 15)
30 memory accesses. length times two. The article is correct.vs. what I said:
> > No, there's one memory access on *average*
Even if it didn’t say that, I think we can figure out from context that the article is talking about worst-case memory accesses.
The article says “len*2 at worst”. There is no intervening text, that’s a direct quote.
> It heavily implies that there's 2 accesses per byte always.
This interpretation is incorrect. The article does not imply this.
It says this, DIRECTLY, not qualifying it as "up to" or "worst case". The next sentence says it can be 2*len, e.g. if you scan the entire length.
Those two sentences feel like something that someone would write if they didn't understand short circuit evaluation.
You read it differently, but your opinion of how it is intended isn't sufficient to refute my interpretation of the text.
My experience with writing answers Stack Overflow is that people in the comments will always figure out a way to interpret an answer as being incorrect, and latch onto it.
There is a tradeoff between clarity and pedantry. You don’t want to simplify something too much where it is no longer insightful, and you don’t want to write something with irrelevant detail that obscures the point you are trying to make.
I understand the concern over excessive pedantry.
If you wish to report errors to the author, there is an email address at the bottom:
> Please drop me email about bug(s) and/or suggestion(s):
"At worst" calculation is just calculating the worst case (string not found) where it has to scan the whole string and... access each byte twice.
It doesn't matter whether we have a worst case or not. They claim two memory accesses per character.
Yes, a worst case of two memory accesses per character. This is obvious, no?
When people analyze algorithm runtime it is not always explicitly stated whether the author is doing worst-case or average-case analysis. So, as a reader, you sometimes have to figure it out.