Most active commenters
  • dekhn(5)
  • lucb1e(3)
  • bogomipz(3)

←back to thread

1764 points fatihky | 12 comments | | HN request time: 0.017s | source | bottom
Show context
buttershakes ◴[] No.12701447[source]
I had almost exactly this same engineering test when google interviewed me in 2006. It was terrible, and left a bad taste in my mouth. Given the complexity of the work I was doing at the time, the entire thing seemed ridiculous.
replies(2): >>12701579 #>>12701983 #
TheCapn ◴[] No.12701579[source]
The inode question gave me flashbacks to my interview with Amazon. They wanted me to explain what a hash function is. I kept giving answers for about 3 minutes explaining hashing, common algorithms, reasons to use it and places it applies.

Recruiter: "I was looking for you to say it's a fingerprint"

So I guess I was wrong, because despite explaining them in decent detail, I didn't use the one keyword.

replies(6): >>12701662 #>>12701711 #>>12701878 #>>12701993 #>>12702618 #>>12702696 #
1. dekhn ◴[] No.12701662[source]
only some hash functions are fingerprints. Other hash functions are the exact opposite of a fingerprint.
replies(1): >>12702099 #
2. lucb1e ◴[] No.12702099[source]
I know some hash functions are not meant to create unique fingerprints (they're to pick a bucket to put/look in), but what do you mean by the opposite of a fingerprint?
replies(1): >>12702209 #
3. dekhn ◴[] No.12702209[source]
The goal of a fingerprint hash is to convert an input space of "large" values to an output space where the output space values are much shorter- typically fixed size and two similar input values have effectively random outputs (without spending the CPU cycles to implement a cryptographic hash). This permits a wide range of optimizations (a document can be fingerprinted, and looked up by its fingerprint, to see if it's a cache, has associated data, etc).

A non-fingerprinting hash function - well, one example of one- is something that for similar inputs, produces the same output (similarity being defined by some distance metric). See, for example: https://en.wikipedia.org/wiki/Locality-sensitive_hashing and https://en.wikipedia.org/wiki/MinHash

Confusingingly, many functions that are used for similarity detection are called Fingerprints, (https://en.wikipedia.org/wiki/Acoustic_fingerprint), but I consider that a distinct use of the term.

replies(2): >>12703128 #>>12703627 #
4. lucb1e ◴[] No.12703128{3}[source]
Thanks for the elaborate answer! I knew about things like acoustic fingerprints but not that people use the term "hash function" to describe something that indicates similarity.

Could something like Hamming distance be called a hash function too? It's not mentioned on its Wikipedia page.

replies(2): >>12703301 #>>12703504 #
5. rockdoe ◴[] No.12703301{4}[source]
No because that works between pairs. It's a comparison method, not a mapping.
replies(1): >>12705123 #
6. dekhn ◴[] No.12703504{4}[source]
it's worth reading and understanding the ideas behind LSH and hamming distance. there are some... fundamental mathematical relationshps there that are still being ... hashed out.
7. bogomipz ◴[] No.12703627{3}[source]
"The goal of a fingerprint hash is to convert an input space of "large" values to an output space where the output space values are much shorter- typically fixed size and two similar input values have effectively random outputs"

But this is also the goal of non-crypto hash function like those used in a data structure no? Basically mapping a large space of inputs to a smaller space of outputs.

I would say the cryptographic hash is one the that has "desirable" security properties, things like not being able to recover the original input message using the hash, a tiny change in the input causes a substantial change in the output, or that its very unlikely that two inputs will produce a collision.

replies(1): >>12703902 #
8. dekhn ◴[] No.12703902{4}[source]
both types of hash convert an input space to an output space where (typically) the input space is much larger.

What matters is whether similar inputs get mapped to the same output. For the case where you want to minimize the probability that two inputs which are highly similar land in the same bucket, you want a crypto hash, although those are expensive so you want a cheaper approximation, which is exactly what fingerprint hashes do. The problem is that as the input values counts approach sqrt(output value size), you're going to start getting collisions, and ideally, you want those collisions to be evenly spaced.

In the case of a similarity hash function, you want the opposite, the closer things are in some metric space, the more likely they end in up in the same bucket.

replies(1): >>12704979 #
9. bogomipz ◴[] No.12704979{5}[source]
"For the case where you want to minimize the probability that two inputs which are highly similar land in the same bucket, you want a crypto hash"

That's what I was trying to say:

"a tiny change in the input causes a substantial change in the output."

But I probably didn't articulate that very well. I think we are saying the same thing.

You mentioned:

"The problem is that as the input values counts approach sqrt(output value size), you're going to start getting collisions"

Can you elaborate on the significant a square root here? Does this relate to the load factor?

replies(1): >>12705069 #
10. dekhn ◴[] No.12705069{6}[source]
https://en.wikipedia.org/wiki/Birthday_problem Basically, you get 50% chance of collision around sqrt(size of table).
replies(1): >>12710335 #
11. lucb1e ◴[] No.12705123{5}[source]
Ah I see. Thanks!
12. bogomipz ◴[] No.12710335{7}[source]
Ah right, a probability theory classic. Thanks, cheers.