Conversation
|
Grabbing this to grade! |
chimerror
left a comment
There was a problem hiding this comment.
Good work!
I added some corrections to your time complexity calculations, but overall this demonstrates sufficient exercise of the information presented and thus is being marked Green.
| anagrams = [] | ||
|
|
||
| for ele in strings: | ||
| if grouped_words.get(create_anagram_key(ele)) == None: |
There was a problem hiding this comment.
Just a minor efficiency thing, if you find yourself calling the same function multiple times with the exact same arguments like you do with create_anagram_key(ele) here, it's usually worth saving the result into a local variable, since every call will recalculate the same data that doesn't change.
| Each subarray will have strings which are anagrams of each other | ||
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(n*m) |
There was a problem hiding this comment.
I'm going to assume that n is the number of words in the list and that by m you mean the number of letters in each word. That being said, note that the call to sorted will actually take O(m * log(m)) time, making this more accurately O(n * m * log(m)).
However, we can make a simplifying assumption since we know that the input list is made up of English words. English words tend not to get long, only about 5 letters per word on average, so the effect of m is going to be dwarfed by the effect of n, since there can easily be hundreds or thousands of words in the list. With that assumption, we can just say the time complexity is just O(n).
| In the case of a tie it will select the first occuring element. | ||
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(n) |
There was a problem hiding this comment.
Don't forget to account for the call to sort on line 42, which will take O(n * log(n)) time and thus be the dominant part of the algorithm for the final time complexity.
kyra-patton
left a comment
There was a problem hiding this comment.
✨🌟 Nice work, Kristina. I left a couple comments. Let me know what questions you have.
🟢
| if grouped_words.get(create_anagram_key(ele)) == None: | ||
| grouped_words[create_anagram_key(ele)] = [ele] | ||
| else: | ||
| grouped_words[create_anagram_key(ele)].append(ele) |
There was a problem hiding this comment.
Instead of calling your helper function three times, consider calling it just once, at the top of the for loop body.
| if grouped_words.get(create_anagram_key(ele)) == None: | |
| grouped_words[create_anagram_key(ele)] = [ele] | |
| else: | |
| grouped_words[create_anagram_key(ele)].append(ele) | |
| anagram_key = create_anagram_key(ele) | |
| if grouped_words.get(anagram_key) == None: | |
| grouped_words[anagram_key] = [ele] | |
| else: | |
| grouped_words[anagram_key].append(ele) | |
| Each subarray will have strings which are anagrams of each other | ||
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(n*m) |
There was a problem hiding this comment.
Yes! Where n is the length of strings and m is the length of the longest word in strings. However, if we assume each word in strings is a valid English word, since those are all of a finite length, we can reduce this to say the solution is O(n)
| Time Complexity: O(n) | ||
| Space Complexity: O(n) |
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions