Skip to content

Conversation

fan-gela
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important?
How can you judge if a hash function is good or not?
Is there a perfect hash function? If so what is it?
Describe a strategy to handle collisions in a hash table
Describe a situation where a hash table wouldn't be as useful as a binary search tree
What is one thing that is more clear to you on hash tables now

Copy link

@kelsey-steven-ada kelsey-steven-ada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I've left a few notes about complexity calculations and some hints for the sudoku problem; overall this is a green =]

@@ -2,28 +2,75 @@
def grouped_anagrams(strings):
""" 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: O(n^2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to be careful about reusing the same variable for complexity calculations. It seems like n is being used as both the number of strings in strings and the number of letters in a word. I would suggest using something like m for the number of letters in a word for clarity.

Looking at the overall Big O, and line 12 in particular, calling the sorted function on a list is an O(m*log(m)) operation. If n is the length of the input strings and m is the length of a word, our overall time complexity would be O(n*m*log(m))


def top_k_frequent_elements(nums, k):
""" 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(n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this solution uses sorted on line 33, our overall time complexity would be O(n) to fill counts + sorted's complexity O(n*log(n)). That gives us O(n + n*log(n)), which we'd simplify to O(n*log(n)).

Comment on lines +39 to +41
for i in range(1, 10):
if str(i) not in row:
return False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Sudoku problem is optional, so no need to revisit, but something to consider if you were wondering about the test failures: this function will return False if a row does not contain all the numbers 1-9.

A row can be valid without being fully filled in yet, and when valid_row is called from valid_subgrid it looks like the row input is 3 items long and would always return false. We want to be sure that there are no duplicate values in a given row or subgrid. One way to do that could be to create a frequency map of the characters in the row, then check that no character other than . has a count greater than 1.

return False
for i in range(0, 9, 3):
for j in range(0, 9, 3):
if not valid_subgrid(table[i:i+3], table[j:j+3]):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like the function declaration for valid_subgrid takes in a second parameter, I'm not sure the second slice here table[j:j+3] gets validated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants