-
-
Notifications
You must be signed in to change notification settings - Fork 301
Article: Hash Tables and Hash Functions #1047
Conversation
|
|
||
| ## Introduction to hashing | ||
|
|
||
| Hashing is designed to solve the problem of needing to efficiently find or store an item in a collection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe link to some good external article on what hashing is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to say link to some Wikipedia article that defines Hashing. where you first use the word Hashing.
| keys = my_hash_table.keys() | ||
| values = my_hash_table.values() | ||
|
|
||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a REPL snippet here.
|
In the implementation part, you can make it absolutely clear that some of these languages come with in-built Hashing support. Like, when you are using Java Hashmap, do mention |
|
@alayek I've implemented your suggestions. I've added links to interesting videos on hashing, if that's alright. |
|
Yes, add as many good resources you can add. In fact, add a separate section on resources altogether! |
Hash-Tables-and-Hashing Functions.md
Outdated
|
|
||
| ## Interesting Links | ||
|
|
||
| - If what I've said doesn't make any sense to you, you may want to check out [this video](https://www.youtube.com/watch?v=x05KubVlh_M). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If what I've said doesn't make any sense to you
I understand you are striking a humorous tone, but better just say it plainly
For further reading
|
@atjonathan @abhisekp @koustuvsinha please check. |
Hash-Tables-and-Hashing Functions.md
Outdated
|
|
||
| Now, in this specific example things work quite well. | ||
| Our array needs to be big enough to accommodate the longest string, but in this case that’s only 11 slots. | ||
| And we do waste a bit of space because, for example, there are no 1-letter keys in our data, nor keys between 8 and 10 letters. But in this case, the waste isn’t so bad either. And taking the length of a string is nice and fast, so is the process of finding the value associated with a given key (certainly faster than doing up to five string comparisons). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the waste the wasted space
And taking Taking
so is and so is
| And we do waste a bit of space because, for example, there are no 1-letter keys in our data, nor keys between 8 and 10 letters. But in this case, the waste isn’t so bad either. And taking the length of a string is nice and fast, so is the process of finding the value associated with a given key (certainly faster than doing up to five string comparisons). | ||
|
|
||
| But, what do we do if our dataset has a string which has more than 11 characters? | ||
| What if we have one another word with 5 characters, "India", and try assigning it to an index using our hash function. Since the index 5 is already occupied, we have to make a call on what to do with it. This is called a collision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index 5 5th index
Hash-Tables-and-Hashing Functions.md
Outdated
| 11 | [Switzerland-Berne] | | ||
|
|
||
|
|
||
| So to find an item we first go to the bucket then compare keys. This is a popular method, and if link list is used the hash never fills up. The cost for `get(k)` is on average `O(n)` where n is the number of keys in the bucket, total number of keys be N. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So to find an item To find an item,
then compare keys. and then we compare keys.
if link list if a list of links
|
Done. |
|
|
||
| ``` | ||
| :rocket: [Run Code](https://repl.it/CVt1) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, @alayek insisted on adding it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries! I trust @alayek ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atjonathan, you meant the repl link right?
LGTM 👍 |
LGTM 👍Let's |
* First Draft of Hashing * Updated Hash-Tables-and-Hashing-Functions.md * Updated Hash-Tables-and-Hashing-Functions.md * Updated Hash-Tables-and-Hashing-Functions.md * Grammar corrections * Grammar corrections * Updated Hash-Tables-and-Hashing-Functions.md
* First Draft of Hashing * Updated Hash-Tables-and-Hashing-Functions.md * Updated Hash-Tables-and-Hashing-Functions.md * Updated Hash-Tables-and-Hashing-Functions.md * Grammar corrections * Grammar corrections * Updated Hash-Tables-and-Hashing-Functions.md
Compiled the first draft on hashing. let me know if I should add anything else.