News for hackers. Stuff that matters.
Re:Avoiding the Adjective Fallacy by TeMPOraL on Tuesday September 29, 2015 @06:41PM (#10300321)
Thanks very, very much for pointing me in the right direction! In the thread you linked, 'Cushman links[0] to a good StackExchange thread[1] that explains some related things that bothered me, and the whole thread also manages to answer my questions regarding arrays.

I wondered about hashtables too. I was actually teaching someone about them recently and had to re-read some CS stuff for it, and in the process I realized that the O(1) access for hashtables doesn't make any sense in the light of explanations I know.

So it turns out that the answer is complicated and in CS curriculum they just handwave you through. It sucks, to be honest, and it's the one thing that always annoyed me about formal education - far too often the teacher/professor stated something as a fact and provided a "proof" with so much confidence that I sort-of assumed it must be so, and realized only months or years later (and after a lot of confusion) that I learned an approximation - maybe a smart one, with good reasons backing it up, but still just an approximation, with important caveats that were never even mentions.

It sorts of make you wonder how much do you really understand about things, even in STEM.

[0] - https://news.ycombinator.com/item?id=9808452

[1] - http://cs.stackexchange.com/questions/1643/how-can-we-assume...

Re:Avoiding the Adjective Fallacy by vinceguidry on Wednesday September 30, 2015 @11:16AM (#10304576)
I think there's a subtlety you might be missing, correct me if I'm wrong.

I stated in my first reply that the growth rate is notated as a function of the size of the input. Big O is itself an approximation, you don't use it if you absolutely have to know all the other factors that don't vary on the size of the input. Such as if they vary on your memory architecture. In practice they tend not to matter, Big-O is sufficient for most purposes.

If you do need the detail, you remove the Big-O and write out your other factors so you can compare them to other algorithms at the right level of detail. There are also other notations you can use that convey other concepts, such as little-o, little-theta, big-theta. When you use a Landau symbol[1], as these are called, you're making an approximate statement by definition.

It's still perfectly fine to call array access O(1), even if your data is stored on Pluto, and it's Odysseus doing a space opera Odyssey for each retrieval, you're still only going there twice. Even if there are sub-algorithms that you are calling within the main one, you're still only calling them a constant number of times. If the first time you go to Pluto to get data it takes 6 months and the second time it takes 30 years, because of complications, it's still constant time.

If you were accessing a linked list stored on Pluto, then you're going to Pluto a number of times depending on how deep in the linked list your data is, assuming it's a dumb probe and it can't figure out where to go once it gets to Pluto and has to come back to earth to figure out what to do next. (go back to Pluto)

If it turns out retrieval time matters, or other factors besides the size of the input, then you can't approximate over them and Big-O ceases to be useful.

[1] http://mathworld.wolfram.com/LandauSymbols.html