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

vi #39

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

vi #39

wants to merge 1 commit into from

Conversation

criacuervos
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? it can improve the efficiency for the lookup of data in your hash table
How can you judge if a hash function is good or not? if it has minimal collisions, and a low loading factor
Is there a perfect hash function? If so what is it? no, there will always be some chance of collision
Describe a strategy to handle collisions in a hash table usually a function will assign the data to the next free location
Describe a situation where a hash table wouldn't be as useful as a binary search tree if you have the same key for a lot of your data, or order is very important
What is one thing that is more clear to you on hash tables now i understand a hash functions main purpose, which is putting a key into a given location to make the lookup time constant

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.

Overall nice work, you hit the main learning goals here. Well done. Do take a look at my minor comments. You did have a typo on submission in anagrams. It's helpful to run the code once prior to submission.

anagram_hash[sorted_string] = [word]
end
end
return anagram_hash.valuesend

Choose a reason for hiding this comment

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

Missing an end after the return

Suggested change
return anagram_hash.valuesend
return anagram_hash.values
end

Comment on lines +43 to +45
k.times do
max = nil
hash.each do |num, value|

Choose a reason for hiding this comment

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

Just note that this iterates k times and each time loops through an hash of n size so this is O(nk)

Comment on lines +28 to 30
# Time Complexity: O(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.

This works, but take a look at my comments on time complexity.

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