Skip to content

Conversation

JansenMartin
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? In practical programming, we spend much of our time looking up data. Hash functions have a look-up time of O(1), which is optimal!
How can you judge if a hash function is good or not? It should: Be consistent, (mostly) map different keys to different values, execute in constant time, and appear to be random.
Is there a perfect hash function? If so what is it? No! They have a mathematically possible worst-case scenario, even though they work practically well.
Describe a strategy to handle collisions in a hash table Chaining makes each bucket of the hash's internal array the head of a linked list. When a collision occurs, the item becomes part of that linked list.
Describe a situation where a hash table wouldn't be as useful as a binary search tree A hash table wouldn't be as useful as a BST if you needed to preserve the order of your data.
What is one thing that is more clear to you on hash tables now The fact we're actually using index numbers to store items inside a hash's internal array. Also, the reason why we use hash tables mainly when we don't care about the order in which our data is stored...it's because we shouldn't count on these index numbers to be next to each other.

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.

Great work, you have the solution to grouped_anagrams well done. See my notes on the time complexity and let me know if you have questions.

# Each subarray will have strings which are anagrams of each other
# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n log n)? (Not sure what Ruby's default sort implementation is...)

Choose a reason for hiding this comment

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

By default I believe it's selection sort for small (10) arrays, and merge sort for others O(n log n)

If n is the number of words and m the length of each word, I would say this is:

O(n * m log m) or O(n) if m is guaranteed to be very small.

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