Skip to content

Shamira#4

Open
MiraMarshall wants to merge 2 commits intoAda-C11:masterfrom
MiraMarshall:master
Open

Shamira#4
MiraMarshall wants to merge 2 commits intoAda-C11:masterfrom
MiraMarshall:master

Conversation

@MiraMarshall
Copy link

@MiraMarshall MiraMarshall commented Sep 16, 2019

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? A good hash function avoids collisions.
How can you judge if a hash function is good or not? A hash function is good if: a) It spreads items over the internal array (avoid collisions). It has a low density - maximum number of collisions, b) Two keys that are similar should get very different indexes, c) Hashing appears to be random, d) It should be consistent! Same key and same internal array = same index, and e) It should be quick O(1).
Is there a perfect hash function? If so what is it? There is no perfect hash function, but ideally there will be O(1) lookup.
Describe a strategy to handle collisions in a hash table Through linear and quadratic probing. If there is a collision, linear probing will check the next bucket. Quadratic probing will use an algorithm/formula to check the next bucket.
Describe a situation where a hash table wouldn't be as useful as a binary search tree
What is one thing that is more clear to you on hash tables now How they are made, using a hash function, and how collisions are handled.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Nice work, you do have a small issue with your time complexity. Let me know if you need more clarification.

// Each subarray will have strings which are anagrams of each other
// Time Complexity: ?
// Space Complexity: ?
// Time Complexity: O(n ^ 2) since the array being sorted has a length less than 10, the sort() method uses InsertionSort.

Choose a reason for hiding this comment

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

But you also have a number of words, so you need to consider the array length as well.

If the words are small you could elect to consider sorting the words as a constant since it's pretty fast, but you definitely need to consider the number of strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments