-
Notifications
You must be signed in to change notification settings - Fork 40
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
Heather #15
base: master
Are you sure you want to change the base?
Heather #15
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.
You have both methods working. Nice job! See my notes on the time complexity.
Well done!
@@ -2,29 +2,73 @@ | |||
|
|||
# This method will return an array of arrays. | |||
# Each subarray will have strings which are anagrams of each other | |||
# Time Complexity: ? | |||
# Space Complexity: ? | |||
# Time Complexity: Would this by O(nlog n) for sorting of the string? |
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.
I would say O( n * m log m) where n is the number of words, and m the length of each word. If you can assume that the words are small, then you could say this is O(n)
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: Would this by O(nlog n) for sorting of the string? | ||
# Space Complexity: O(n + m), n is the size of the array and m is the size of the hash |
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.
Since the size of the hash depends on the size of strings
I would say O(n)
end | ||
|
||
# This method will return the k most common elements | ||
# in the case of a tie it will select the first occuring element. | ||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(nlog n) because of the sorted array is at least |
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.
True! Could this be faster without sorting?
|
||
answer_arr = [] | ||
k.times do |
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 looks like a loop that runs k
times and a nested loop which runs maybe n
times.
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions