Skip to content
This repository was archived by the owner on Apr 1, 2021. It is now read-only.

Conversation

@ds-249
Copy link
Contributor

@ds-249 ds-249 commented May 27, 2016

Compiled the first draft on hashing. let me know if I should add anything else.

@ds-249 ds-249 changed the title First Draft of Hashing Article: Hash Tables and Hash Functions May 27, 2016
@alayek alayek self-assigned this May 27, 2016

## Introduction to hashing

Hashing is designed to solve the problem of needing to efficiently find or store an item in a collection.
Copy link
Member

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?

Copy link
Member

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.

@Rafase282 Rafase282 added the QA label May 27, 2016
keys = my_hash_table.keys()
values = my_hash_table.values()

```
Copy link
Member

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.

@alayek
Copy link
Member

alayek commented May 27, 2016

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 java.util.HashMap in the import. Also mention HashSet if you can.

@ds-249
Copy link
Contributor Author

ds-249 commented May 27, 2016

@alayek I've implemented your suggestions. I've added links to interesting videos on hashing, if that's alright.

@alayek
Copy link
Member

alayek commented May 27, 2016

Yes, add as many good resources you can add. In fact, add a separate section on resources altogether!


## 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).
Copy link
Member

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

@alayek
Copy link
Member

alayek commented May 27, 2016

@atjonathan @abhisekp @koustuvsinha please check.


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).
Copy link

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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index 5 5th index

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.
Copy link

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

@ds-249
Copy link
Contributor Author

ds-249 commented May 27, 2016

Done.


```
:rocket: [Run Code](https://repl.it/CVt1)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line...

Copy link
Contributor Author

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

Copy link

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 ❤️

Copy link
Contributor Author

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?

@ghost
Copy link

ghost commented May 27, 2016

LGTM 👍

@alayek
Copy link
Member

alayek commented May 27, 2016

LGTM 👍

Let's :shipit: 📦

@ghost ghost merged commit 24d604f into freeCodeCamp:master May 27, 2016
@BerkeleyTrue BerkeleyTrue removed the QA label May 27, 2016
@alayek alayek assigned Rafase282 and unassigned alayek May 27, 2016
@ds-249 ds-249 mentioned this pull request May 27, 2016
23 tasks
@ds-249 ds-249 deleted the datastructures branch May 27, 2016 17:24
trishulpani pushed a commit to trishulpani/wiki that referenced this pull request May 28, 2016
* 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
tanham pushed a commit to tanham/wiki that referenced this pull request Jun 2, 2016
* 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
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants