Teacher: Okay class solve this problem: Given an array of integers find the number of pairs in the array which sum to a given number. I want an O(n) solution.
Eric: Oh, I'll just use a hash table. Let's check my answer with Ilyssa.
Eric: Hey Ilyssa, here is my idea: you make a hash table to store counts of each element, and then make a pass through the array looking for the count of its pairing element, which is just sum minus the current element. Now, this is in O(n) because the first pass takes O(n) steps and each step is O(1) because hash table lookup is O(1) -
Ilyssa: Lol, what makes you think that?
Eric: Well you hash in O(1) time and-
Ilyssa: Say what? Hashing in O(1) time? What so the hashing function only reads a fixed number of bits of the input?
You might be reading a pirated copy. Look for the official release to support the author.
Eric: Well, it can do that.
Ilyssa: So you end up with a fixed number of possible hashes. A degenerate hash table.
Eric: Well, operations on word-size integers are O(1) right?
Ilyssa: Lol, if you assume the input size is fixed then why are you doing asymptotic analysis?
Eric: By that logic addition and subtraction aren't O(1) either.
Ilyssa: They're not. They're both linear with respect to the length of the input.
Eric: We're dealing with RAM machines here. Word-size arithmetic is O(1).
Ilyssa: And arithmetic in general is not.
Eric: And we're not dealing with arithmetic in general. We're doing real-world machine-word-size arithmetic.
Ilyssa: You have no business doing asymptotic analysis if you're fixing the input size.
Eric: You are a pedant of the highest degree.
Ilyssa: Try again.