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

Raisah #28

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

Raisah #28

wants to merge 2 commits into from

Conversation

raisahv
Copy link

@raisahv raisahv commented Mar 10, 2020

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? A good hash function miminizes the number of possible collisions, and thus reduces the number of times the hash has to resize itself
How can you judge if a hash function is good or not? If it does a good job spreading elements over different buckets (linked lists will be small) and search time for an item will be close to O(n)
Is there a perfect hash function? If so what is it? No, there is no universal hash function but there is no guarantee the hashing function will prevent all possible collisions.
Describe a strategy to handle collisions in a hash table Have a linked list at each index of the hash table, insert the new object onto the linked list any time there is a collision
Describe a situation where a hash table wouldn't be as useful as a binary search tree If the data set doesn't have unique key values
What is one thing that is more clear to you on hash tables now Different methods for collision handling in hash tables

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.

Very nice work including Sudoku. Take a look at my comments and let me know if you have questions. Otherwise excellent work!

Comment on lines +5 to 7
# Time Complexity: O(nm) because the method will always iterate through each string (n) in strings and then each string will be compared to all hashes (m) that have been created, which in the worst case could be the same as the number of strings
# Space Complexity: O(n) because the size of anagrams_grouped and hash_groups will grow linearly with the size of strings in the worse case
def grouped_anagrams(strings)

Choose a reason for hiding this comment

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

This works with good time/space complexity, but could use with some refactoring.

Comment on lines +52 to 54
# Time Complexity: O(nlogn) because the sort_by method will have the time complexity of quick sort
# Space Complexity: O(n) because the size of the variables will change linearly with the size of list
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.

👍 Correct, nice work

Comment on lines +88 to 90
# Time Complexity: O(n) because at method must go through the table 3 times to check for each sceniario to be valid (row, column, 3x3 grid)
# Space Complexity: O(1) because the size of the variables created is constant. (if the grid is greater than 9x9 this might change for the corners array)
def valid_sudoku(table)

Choose a reason for hiding this comment

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

This works, but the method is pretty long and could use some refactoring. Maybe breaking some things into helper methods.

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