You are viewing a single comment's thread from:
RE: Easy Tutorial: Computer Programming for DUMMIES (recursion made simple!)
Why would you need a hash table?
I only used a stl vector for the contatiner because I didn't want to deal with dynamically allocated arrays of a particular size and then using memory allocation / deallocation in the pseudocode. I could've said
int fibs[n+1];
but ... there's something really dissatisfying about doing that when n is not known at run time ...
But if you mean that the hash function is the trivial
hash(i) = i
function and that you are saying that
fibs[hash(i)] <- F(i)
where F(i) is the i'th Fibonacci number, then, yes, I suppose you could do that.
No, I said it is like a hash table... I didn't say that we need a hash table! What I meant is that the array is like a hash table that holds all of the Fibonacci numbers, and calling fibs[x] is like the hash function for it. The more I try to explain this, the less this resembles a hash table, so I'm going to stop right there, haha! It just reminded me of a hash table because you can look things up very quickly (just like you can look up each Fibonacci number very quickly because they are already calculated in an the array).