Check out a free preview of the full Introduction to Data Structures for Interviews course

The "Hash Table: Remove" Lesson is part of the full, Introduction to Data Structures for Interviews course featured in this preview video. Here's what you'd learn in this lesson:

Bianca implements the remove() method in the hash table data structure.

Preview
Close

Transcript from the "Hash Table: Remove" Lesson

[00:00:00]
>> Bianca Gandolfo: So remove is gonna be really similar to retrieve, except that you need to delete it.
>> Bianca Gandolfo: Yeah.
>> Bianca Gandolfo: So again, even though these looks like they are linear, if you have a hashing function that is not my hashing function, you shouldn't run into these kind of collisions.

[00:00:29]
Another thing to think about is if you're implementing your hash table is that once you get 50% full, you wanna double the size. And so this will stop collisions from being really dense. So once you resize it, you need to, so that would happen in the insert. So when you insert, if the size is greater than 50% of the length of your hash table storage.

[00:00:58]
So if your table size is 25 and you can have your input size starts at 0, but you increment it every time. If this is 50% or more of your table size which in this case, it's 13, then you want to double the table size and then you need to run your hash function with the new table size on every input.

[00:01:36]
And this is called resizing, it's another thing that you can do with a hash table and it's part of the implementation. And so this is another thing that sounds like it's crazy expensive. But in the big scheme of things, it averages out and we don't really worry about it.

[00:01:51]
Cuz it happens just once every once in a while, especially if you're initializing your hash table at a size that's appropriate for your data set. It doesn't really make a difference in the big picture.
>> Bianca Gandolfo: So that's hash table. Any questions about hash table?
>> Speaker 2: Is there a situation that's pretty easy that's real world that you would use a hash table in?

[00:02:33]
>> Bianca Gandolfo: Like make my own harsh table?
>> Speaker 2: Yeah.
>> Bianca Gandolfo: Not really. Yeah, good question. Yeah, you could just use an object or a map or set, depending on your used case.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now