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

Branches - Michaela #22

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

Conversation

michaela260
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? If you don't have a good hash function you will have collisions more often
How can you judge if a hash function is good or not? You can judge if it's good by how many collisions it has.
Is there a perfect hash function? If so what is it? There is no perfect hash function, you just try to minimize collisions.
Describe a strategy to handle collisions in a hash table You can handle collisions by putting them in a linked list. You could also use linear probing to try to avoid collisions.
Describe a situation where a hash table wouldn't be as useful as a binary search tree If you don't have unique keys to use it might be better to use a binary search tree. Also, if you need to do a lot of sorting a binary tree might be better.
What is one thing that is more clear to you on hash tables now It is more clear how they work under the hood - i.e. they still have to be built in a fixed area.

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.

This all works, but see my notes on time/space complexity. Otherwise well done.

Comment on lines +5 to 9
# Time Complexity: O(n * m) where n is the number of characters in the longest word and m is the size of the input array
# It might actually simplify to just O(n) where n is the total number of input charcters, because you're only sorting each word once
# Space Complexity: O(n) where n is the size of the input array

def grouped_anagrams(strings)

Choose a reason for hiding this comment

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

👍 You are right on time complexity except that it would be better said that time complexity is O(n) if the words are guaranteed to be less than a certain length.

Comment on lines +27 to 29
# Time Complexity: O(n) where n is the size of the array
# Space Complexity: O(n) where n is the size of the array
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.

Yes, but you are sorting all the values so this is worst case O(n log n)

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