Skip to content

Conversation

norrise120
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? It is important so that the keys are distributed evenly, resulting in less collisions and quicker look up.
How can you judge if a hash function is good or not? It should distribute keys evenly and keep similar keys separated. It should also appear random.
Is there a perfect hash function? If so what is it? A perfect hash function would have O(1) look-up every time. I don't think this has been achieved yet.
Describe a strategy to handle collisions in a hash table One way to handle collisions is chaining in which buckets (either immediately or some spaces) next to occupied values are used.
Describe a situation where a hash table wouldn't be as useful as a binary search tree Hash tables are not good for recalling sorted values!
What is one thing that is more clear to you on hash tables now After this lesson, I have a much clearer understanding of the structure of a hash table from when we first covered hash tables.

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.

Well done, you got this one. Well done.

# Space Complexity: ?
# Time Complexity: O(n), where n is the number of words in strings, for the each loop
# I'm not sure what the time complexity is for string.chars.sort.join, but I would guess
# O(m), where m is the number of letters in strings

Choose a reason for hiding this comment

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

Not quite, remember the best sorts are O(m log m). You can make the argument that if the words are small, then the time complexity is O(n) where n is the number of words.

If the words are potentially long, then it could be O(n * m log m) where n is the number of words and m is the length of each word.

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.

2 participants