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

Charlotte - Space #29

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

Charlotte - Space #29

wants to merge 4 commits into from

Conversation

charlottea13
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? they are fast - 0(1) time complexity for insert/delete/lookup, to avoid collisions as the load factor increases
How can you judge if a hash function is good or not? 1. fast 2. values are evenly distributed throughout 3. the hashing is random 4. keys are close - values spread out.
Is there a perfect hash function? If so what is it? yes. it's one-to-one mapping ie: a person to a unique id
Describe a strategy to handle collisions in a hash table quadratic probing - looks at indexes away from the current probing position - say 5 indexes and then 20 indexes and so on.
Describe a situation where a hash table wouldn't be as useful as a binary search tree when there are duplicate keys
What is one thing that is more clear to you on hash tables now if you can use this data structure - you should - b/c of the time complexity

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 Charlotte, you hit most of the learning goals with just 1 test failing. You also need to take a look at time complexity a bit. This is something to work on here.

Comment on lines +4 to 7
# Time Complexity: 0(1)
# Space Complexity: 0(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.

👍 , however your time complexity is off. You loop through all the strings so it's a minimum of O(n). If you assume the strings are all small then the sorting can be ignored.

lib/exercises.rb Outdated
Comment on lines 35 to 37
# Time Complexity: 0(1)
# Space Complexity: 0(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 is most of the solution, the only weakness is that the sort_by you're doing doesn't preserve the order the elements were encountered in. You also have the time complexity wrong because you have a loop through all the elements and you're sorting them.

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