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

Hash Practice CS FUN #61

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

Hash Practice CS FUN #61

wants to merge 2 commits into from

Conversation

ASY13
Copy link

@ASY13 ASY13 commented Jul 21, 2022

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important?

Quicker than searching for lists/arrays.

How can you judge if a hash function is good or not? |

  1. The hash value is determined by the data being hashed.
  2. Uses all input data 3. It has uniformly distributed the data across the entire set of possible hash values.

Is there a perfect hash function? If so what is it? |

  • Can be constructed that maps each of the keys to a distinct integer with no collisions.
    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/

@chimerror
Copy link

Grabbing this to grade!

Copy link

@chimerror chimerror left a 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: ?

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:

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):

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.

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