Skip to content

maple - ruiz #58

Open
Jruiz9312 wants to merge 1 commit intoAda-C16:masterfrom
Jruiz9312:master
Open

maple - ruiz #58
Jruiz9312 wants to merge 1 commit intoAda-C16:masterfrom
Jruiz9312:master

Conversation

@Jruiz9312
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

@chimerror
Copy link

Grabbing this to grade!

Copy link

@chimerror chimerror left a comment

Choose a reason for hiding this comment

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

Pretty good...

There is a bug in your otherwise correct anagrams solution that causes only the last string in each anagram group to be returned, not the entire group. This causes the automated tests to fail, so I am marking this Yellow to encourage you to fix that bug. If the bug is fixed, I'm fine with moving this up to Green.

I also added corrections to your complexity calculations, as well as some more hints on the sudoku problem.

if word_sorted not in anagram_dict:
anagram_dict[word_sorted] = [string]
else:
anagram_dict[word_sorted] = [string]

Choose a reason for hiding this comment

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

Oof, this causes a pretty bad bug that means only the last string of each anagram group is returned, rather than all the strings in that group. I think you meant to append to the list here rather than replacing the value.

However, the solution is otherwise correct, so I'm only going to mark this Yellow. I will upgrade to Green upon this bug being fixed.

Time Complexity: ?
Space Complexity: ?
Time Complexity: O(n)
Space Complexity: O(1)

Choose a reason for hiding this comment

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

As we possibly add an entry to anagram_dict for each word in strings (in the case no words are anagrams of each other), the space complexity here is O(n).

Time Complexity: ?
Space Complexity: ?
Time Complexity: O(n)
Space Complexity: O(1)

Choose a reason for hiding this comment

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

Likewise, in this case we add an entry to most_common for each number in nums so the space complexity here is O(n).

else:
if row.count(element) >1:
return False
if [row[i] for i in range(9)].count(element)>1:

Choose a reason for hiding this comment

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

I know this problem is optional but I just want to note that the list comprehension [row[i] for i in range(9)] will not actually return the columns, but just a copy of row again (since all rows are 9 elements long).

To get the columns, you'll have to iterate over table not row.

return False
if [row[i] for i in range(9)].count(element)>1:
return False
if [table[i][j] for i in range(3) for j in range(3)].count(element) >1:

Choose a reason for hiding this comment

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

Likewise, this will always return the first subgrid ((0, 0) to (2, 2)) every iteration, so to fully solve this, you will likely need to more explicitly iterate through all the subgrids rather than using a list comprehension.

row, column or 3x3 subgrid
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(n2)

Choose a reason for hiding this comment

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

This would be correct (even given your current buggy implementation) if we were taking in arbitrary nxn grids, but as we are only taking in 3x3 grids, the run time is constant and thus O(1).

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