-
Notifications
You must be signed in to change notification settings - Fork 43
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
Linnea - Branches #23
base: master
Are you sure you want to change the base?
Conversation
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.
Overall well done, see my minor comments. You hit all the learning goals here. Nice work.
# Time Complexity: O(n*m) | ||
# Space Complexity: O(n) | ||
|
||
def grouped_anagrams(strings) |
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.
This works but your time complexity is O(n * m log m) where n is the number of strings and m is the length of the strings since you are sorting.
If the strings are guaranteed to be within a certain length, you could drop the m term and it would be O(n).
end | ||
|
||
k.times do | ||
max_key = hash.key(hash.values.max) |
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.
.key
searches the values array for a matching value and returns it's key. So .key
is O(n) (not to mention that .max
is also O(n).
# Time Complexity: O(n * m) where n is the length of the list and m is the size of k | ||
# Space Complexity: O(n + m) where n is the hash and m is the elements results array | ||
def top_k_frequent_elements(list, k) |
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.
Correct, although I would have put time complexity as O(nk) instead of O(nm).
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions