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

space kate #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

space kate #27

wants to merge 1 commit into from

Conversation

katemyer
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? To speed up look up times, critical when dealing with lots of data.
How can you judge if a hash function is good or not? Good hash fx are easy to compute and avoid collisions. Bad hash fx product results with multiple values assigned to same key.
Is there a perfect hash function? If so what is it? Nothing is perfect in life. But, if a hash could be perfect, it would be one that naps the set of actual key values to the table without any collisions.
Describe a strategy to handle collisions in a hash table You can do separate chaining == make each cell of a hash table point to a linked list of records that have the same hash function value. Or, you can do open addressing which is trying to find the next open slot or address in the hash table.
Describe a situation where a hash table wouldn't be as useful as a binary search tree When you need to iterate over all values in a list, finding the largest or smallest key.
What is one thing that is more clear to you on hash tables now The hash function itself, you actually need a function to create the table. It's not the same as a hash.

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 Kate, you hit the learning goals here. Well done.

Comment on lines +4 to 7
# Time Complexity: O(n log n)
# Space Complexity: O(n)

def grouped_anagrams(strings)

Choose a reason for hiding this comment

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

Since you're sorting the words and English words are small this method actually depends on the number of words, not the length of them.

So it's O(n * m log m) where m is the length of the words, or if you assume the words are short O(n)

key = word.chars.sort.join
#check if key is in the hash, push the word into the hash
#else, set the key as the word
if hash.key?(key)

Choose a reason for hiding this comment

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

Just a bit more compact.

Suggested change
if hash.key?(key)
if hash[key]

Comment on lines +38 to 40
# Time Complexity: O(n log n)
# Space Complexity: O(n)
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.

👍

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