Skip to content

Conversation

@Kbhlee2121
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important?
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
Describe a situation where 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

@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.

Good work!

I added some comments about your anagrams time complexity calculation, and the assumption you made for the top k most frequent elements, but overall this looks good enough for a Green.

Each subarray will have strings which are anagrams of each other
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(n^2)

Choose a reason for hiding this comment

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

When doing time complexity calculations, you can't really reuse the same variables to represent different factors. For example, here, you're using n for both the number of strings in the list, and the number of characters in the strings, which are independent factors. So this would more properly be O(n*m) where n is the number of strings in the list, and m is the number of characters in the strings.

However, we can also make an simplifying assumption since we know our input is a list of English words. Words in English don't get too long (5 letters per word on average), so the effect of the number of characters in the word is pretty bounded, especially compared to the number of words in the list (which could easily be hundreds or thousands of words). As such, we can just say the time complexity is O(n).

freq_values.sort(reverse=True)
# k number of max frequencies. Assumes if k = 2, and there are more than one with the 2nd highest frequency
# ex output = [1,1,2,2,3,3,3]
# 1 and 2 are tied so they are both added to max_values and the output will have 3 elements in a list. output = [1,2,3]

Choose a reason for hiding this comment

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

In this case, we've generally been expecting that you drop down to k even if there are ties, but this is a perfectly fine assumption to make, so I'm not going to ding you for it.

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