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

Amy P #4

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

Amy P #4

wants to merge 2 commits into from

Conversation

aphunk
Copy link

@aphunk aphunk commented Sep 15, 2019

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? A good hash function is important, as it can make for a quick lookup, as well as avoid collisions through even distribution of values.
How can you judge if a hash function is good or not? A good hash function is quick to compute hash values, distributes values evenly, keeps a good amount of distance between keys with similar values, and has a seemingly random distribution pattern.
Is there a perfect hash function? If so what is it? No, sir.
Describe a strategy to handle collisions in a hash table Using quadratic probing to find a new designation for the collided value -- this is additionally beneficial in avoiding clustering.
Describe a situation where a hash table wouldn't be as useful as a binary search tree A binary search tree is more useful in situations where the order of the data matters.
What is one thing that is more clear to you on hash tables now The application of hash tables in computing is more clear now, as well as the idea of a good hash function.

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, you did the requirements here, well done.

# This method will return an array of arrays.
# Each subarray will have strings which are anagrams of each other
# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n) where n is the number of elements in the array

Choose a reason for hiding this comment

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

Assuming the words are small, yes.

end

top_elements = Array.new(k)
return top_elements = hash.sort_by{ |key, value| value }

Choose a reason for hiding this comment

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

You just need to limit the return to the 1st k elements, but otherwise you have it.

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