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

Earth - Christina Minh #23

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

Conversation

christinaminh
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? To uniformly distribute hash values and allow constant look-up time complexity
How can you judge if a hash function is good or not? A good hash function is computable in constant time and minimizes collisions.
Is there a perfect hash function? If so what is it? No, because we never know all the possible keys in advance.
Describe a strategy to handle collisions in a hash table Chaining uses a linked list to store collided keys. The array element serves as the head of the linked list.
Describe a situation where a hash table wouldn't be as useful as a binary search tree If a dataset didn't have unique keys, than a hash table wouldn't be as useful as a binary search tree.
What is one thing that is more clear to you on hash tables now How collisions are handled

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 Christina. You hit the main learning goals here. I had a few comments on big O regarding the 2nd method, but otherwise this is well done. You even got the Sudoku problem. Well done.

Comment on lines +4 to 10
# Time Complexity: O(n * m * log m)
# where n is the number of strings in the array to iterate over,
# and m is the number of characters to sort in a string (m log m),
# Space Complexity: O(n * m) from sorting characters (m) and returning a new array (n)
# where n is the number of strings in the array
# and m is the number of characters in a string
def grouped_anagrams(strings)

Choose a reason for hiding this comment

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

👍

Comment on lines +27 to 31
# Time Complexity: O(n + m log m) where n is the number of elements in the list and
# and m is the number of unique elements to sort (m log m)
# Space Complexity: O(m * k) where m is the number of unique elements to put in hash
# and k is the number of elements to return
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.

👍 I would say this is O(n log n) since k < n, and you're potentially sorting a hash of n elements.

For space complexity since k < n, and you make a hash of potentially n elements this is O(n).

Comment on lines +58 to 60
# Time Complexity: O(1) constant time to iterate over table that is always 9x9
# Space Complexity: O(1)
def valid_sudoku(table)

Choose a reason for hiding this comment

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

👍 Nicely done.

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