-
Notifications
You must be signed in to change notification settings - Fork 77
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
Hash Practice CS FUN #61
base: master
Are you sure you want to change the base?
Conversation
Grabbing this to grade! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty good...
Since your anagrams solution uses a list rather than a dictionary, it has a much worse running time, and fails to demonstrate knowledge of the material. However as you seem to otherwise demonstrate that knowledge on the other problems, I am marking this Yellow. I encourage you to look at using a dictionary for your anagrams solution, and if successful, I'll move to Green.
I also added a quick naming note as well as some missing complexity calculations, but neither of those issues are major.
@@ -1,29 +1,123 @@ | |||
|
|||
def grouped_anagrams(strings): | |||
""" This method will return an array of arrays. | |||
Each subarray will have strings which are anagrams of each other | |||
Time Complexity: ? | |||
Space Complexity: ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing complexity calculations here but I haven't been dinging people for it, simply calling attention to it.
for i in range(1, len(strings)): | ||
cur_str = strings[i] | ||
cur_str_dict = create_dict(cur_str) | ||
if cur_str_dict in dict_list: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling in
on a list takes O(n) time, so by using the list dict_list
instead of a dictionary, your entire solution takes O(n^2) time. You can achieve O(n) time by replacing dict_list
with a dictionary, and that is the intended solution given the material, so I'm going to mark this as Yellow and encourage you to attempt that solution.
|
||
|
||
|
||
def create_dict(word): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create_dict
is a bit too generic of a name, I think I would call this something like create_frequency_dict
, because otherwise, my expectation is that this just creates an arbitrary dictionary rather than the specific frequency dictionary that is created here.
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
Quicker than searching for lists/arrays.
How can you judge if a hash function is good or not? |
Is there a perfect hash function? If so what is it? |
Describe a strategy to handle collisions in a hash table | 1. Resizing by copying all entries. 2. Incremental resizing.3.Monotonic keys.
Describe a situation where a hash table wouldn't be as useful as a binary search tree | Hash is for unordered collection vs. binary search tree is for storing an ordered collection
What is one thing that is more clear to you on hash tables now | This was very helpful to understand the bigger picture: https://www.freecodecamp.org/news/the-codeless-guide-to-hash/