-
Notifications
You must be signed in to change notification settings - Fork 39
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
Water - Christabel #16
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.
Nice work Christabel, you hit the learning goals here. Well done.
hashes = [] | ||
strings.each do |word| | ||
word_hash = {} | ||
word = word.chars.sort #sort is O(n)? |
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.
Sort is O(n log n), it's mergeSort
# Time Complexity: O(2nm + p) where n is the length of the list passed to grouped_anagrams, and m represents the number of chars in each string and p is the number of unique char hashes | ||
# == O(nm) | ||
# Space Complexity: Um O(2n) == O(n) since I am creating an array equal to the length of the passed in list and the worst case size for the meta_hash is also the length of the passed in list? | ||
|
||
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.
I'd say this is O(n * m log m) where m is the number of chars in each string and n is the length of the array.
# Time Complexity: O(3n) == O(n) where n is the length of the passed in list | ||
# Space Complexity: O(n) since the worst case is that the elements hash is the full length of the passed in list | ||
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.
This is O(n log n) because sorting is O(n log n)
# Time Complexity: oh goodness. this is a mean question. I'm going with O(1) since the grid is always 9x9, but let me show my work here... | ||
# O(9) == O(1) for checking for uniqueness in all rows and columns | ||
# O(9) == O(1) for building the 2darray of all subgrid values | ||
# O(9^2) == O(1) for checking for uniqueness in all subgrid values | ||
# Space Complexity: for lack of more confident alternate logic, I'm going with the same answer as above, O(1) since the grid is a fixed size so the worst case for the created row, column, and subgrid hash are all worst case space complexities of O(9) and the array of subgrid values is a fixed size of O(81) | ||
def valid_sudoku(table) |
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 are correct that the time/space complexity is O(1)
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions