Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Earth - Jasmine #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Earth - Jasmine #19

wants to merge 2 commits into from

Conversation

jasyl
Copy link

@jasyl jasyl commented Apr 28, 2021

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? A good Hash Function prevents too many collisions which will keep loop up time O(1)
How can you judge if a hash function is good or not? A good Hash function is consistent, it'll output the same value for the same input. It should map different keys to different values and have even distribution, seemingly random. It should also execute in constant time.
Is there a perfect hash function? If so what is it? No, there's still a potential of collisions with any method or clustering. Some methods are better than others depending on circumstances and trade offs.
Describe a strategy to handle collisions in a hash table Chaining is a common strategy where each slot of an array will point to a linked list. That way if multiple keys map to the same index, the values will be able to extend into the linked list. Not great if all keys are mapped to the same list.
Describe a situation where a hash table wouldn't be as useful as a binary search tree If you need to keep of an order, min /max values or sorting, a BST may be the better data structure.
What is one thing that is more clear to you on hash tables now There are many ways to approach a hash function. All with pros and cons. Also that hashes are built on array, that helps visualize what's going on.

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.

Really nice work Jasmine, you hit everything here. Well done!

Comment on lines +4 to 8
# Time Complexity: O(n * klog(k)) where n is the number of strings and k is the length of each string.
# Space Complexity: O(n) - using hash to store each word.
# Does having an array as a key increase the space complexity?

def grouped_anagrams(strings)

Choose a reason for hiding this comment

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

👍

Comment on lines +26 to 28
# Time Complexity: O(nlog(n)) - due to using sort_by
# Space Complexity: O(n) - hash could potentially hold n unique values.
def top_k_frequent_elements(list, k)

Choose a reason for hiding this comment

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

👍 Very compact and yet readable.

Comment on lines +48 to 50
# Time Complexity: O(1) because the grid is a fixed size.
# Space Complexity: O(1) even though we're using multiple hashes it's O(1) because the grid is a fixed size
def valid_sudoku(table)

Choose a reason for hiding this comment

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

👍

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