Skip to content

Spruce: Kaitlyn#47

Open
kaitlyngore wants to merge 2 commits intoAda-C16:masterfrom
kaitlyngore:master
Open

Spruce: Kaitlyn#47
kaitlyngore wants to merge 2 commits intoAda-C16:masterfrom
kaitlyngore:master

Conversation

@kaitlyngore
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? It determines how frequently collisions occur (and the goal is to minimize them).
How can you judge if a hash function is good or not? You can see if it is consistent, maps different keys to different values, is O(1) for time complexity, and creates keys that appear random.
Is there a perfect hash function? If so what is it? No
Describe a strategy to handle collisions in a hash table You can use chaining which involves making each element of the hash table's internal array (bucket) the head of a linked list.
Describe a situation where a hash table wouldn't be as useful as a binary search tree When there are not unique keys that can be used
What is one thing that is more clear to you on hash tables now It is more clear to me how look-up for a has table is constant whereas look-up for an array is not.

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

Good work! I left some comments about your complexity calculations, as well as a hint on the subgrid part of the sudoku problem, but otherwise this looks good enough for a Green!

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.

My guess is that you're trying to account for the sort in line 10, but this answer is wrong in that case. sorted takes up O(m * log(m)) time where m is the number of characters in the word. Since I'm assuming n stands for the number of words in the list, that would make it O(n * m * log(m)). When doing these, you can only really have each variable stand for one thing.

However, under the assumption that our input is made up of English words, we can "ignore" the call to sorted. English words tend to be short, about 4.7 letters per word on average, so the effect of the length of the words would be quickly dwarfed by the number of words in the list. There may be hundreds or thousands of words in the list reasonably, but probably not that many letters in the words.

With that simplification we can just say the time complexity is O(n), where n is the number of words in the list.

Your space complexity calculation and implementation are fine, though.

In the case of a tie it will select the first occuring element.
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(n) + O(n log n)??

Choose a reason for hiding this comment

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

This is almost right. Usually when doing big-o notation, everything goes in one "O" so your answer would be better expressed as O(n + n * log(n)). However, in that case, as the n * log(n) part will increase in size quicker than the n part (like when n^2 or n * n dwarfs n), we can just only keep that part to reduce down to O(n * log(n)).

Your space complexity and implementation are fine, though.

column_dictionary[table[j][i]] = "yay!"

# check sub-grid
# ????

Choose a reason for hiding this comment

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

As this question is optional, not finishing this is fine, but to give a bit of a hint...

I don't think you are going to really be able to do this in the same loop as the rows and columns. You are going to need another nested loop over the 3x3 sub grid, which is itself nested in a loop over each sub grid. In the instructor solution, the indices of the the subgrids are actually written out as a constant array of pairs, but there's other ways.

But once again, no need to answer this, just giving a hint in case you want to come back and answer this.

Time Complexity: ?
Space Complexity: ?
Time Complexity: O(n^2)
Space Complexity: O(n)

Choose a reason for hiding this comment

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

These calculations are correct given your current algorithm, but a full solution will probably push the time complexity up.

At the same time, since we assume all grids are 3x3 the number of steps and space used will always be constant so you could consider this to be O(1) in space and time complexity. Of course, allowing for any size of boards will change that, but in this case, it's always 3x3.

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