How does hashing work?
A free video tutorial from Jonathan Rasmusson
Ex-Spotify Engineer, The Agile Samurai
4.5 instructor rating • 5 courses • 36,586 students
Learn more from the full courseData Structures and Algorithms Bootcamp
How to ace your Silicon Valley style coding interview
06:27:06 of on-demand video • Updated May 2020
- How to answer commonly asked Silicon Valley style interview questions
- Demonstrate knowledge and mastery of data structures and algorithms
- How to pass Silicon Valley style technical interviews
- Interview confidently
- Land your dream job
English So there's three parts that go into building a hash table. You got the hash function, converting that hash into an index and then handling collisions. Let's start by taking a look at what a good hash function is. A hash function is a method that takes any object and calculates an almost unique numerical representation of that object that can be used as a key for look up later. A good hash function is fast. It gives a good even distribution of numbers and it minimizes collisions. More on that later. Now each object we store on hash table has to have a hash function that's responsible for generating its own hash code. In our lab, We're just going to use the built in Java string hash could function that inherently comes with Java but regular objects can calculate their own hash code too. Take this person object for example. Here we have a regular Java object called person with some unique attributes and we can calculate its hash code by taking those attributes multiply them by a prime number like 31 and returning the result. That would be the key or the hash code that we could use to look up this person objects later on in our hash table. And now that we've got the hash for our object we need to convert that into an index.