1

I have two inputs (example): "Smooth Criminal" and "Billie Jean", that return the same index key, when run through a hash function.

In the array[], i want to save the path to the songs MP3 file on my harddisk.

Let's say they both return 0 as index key, so "Smooth Criminal" goes to index: 0 and "Billie Jean" goes to index 0 + 1^2 = 1.

How would i find the filepath of "Billie Jean" in the array, when both songs return the same key?

Thanks

Kenci
  • 4,794
  • 15
  • 64
  • 108

1 Answers1

1

By quadratic probing, again. You first check index 0, where you find "Smooth Criminal"; that's not what you were looking for. So, you look at index 1, where you find "Billie Jean"; you're done.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • If i want to save the file path of the song in the array, based upon it's song title, i run the hash function with the title, which produces the same key in both cases (0). When searching, i dont know the filepath to match for? – Kenci Dec 27 '11 at 12:06
  • 1
    The hash comparison is only a surrogate for the key comparison. After equal hash values you should still check the actual keys. – wildplasser Dec 27 '11 at 12:10
  • Sorry if i sound a little confused, but how do i cehck the actual keys? From my array i can only get the index number og the filepath of the song? – Kenci Dec 27 '11 at 12:13
  • How did you detect the collision on the first probe? The second probe+collision+check is not fundamentally different. – wildplasser Dec 27 '11 at 12:36