-
Notifications
You must be signed in to change notification settings - Fork 76
Cedar - Kristin L #50
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
base: master
Are you sure you want to change the base?
Conversation
|
Grabbing this to grade! |
chimerror
left a comment
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.
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) |
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.
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] |
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.
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.
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions