Skip to content
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

Ari #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Ari #7

wants to merge 5 commits into from

Conversation

aribray
Copy link

@aribray aribray commented Sep 16, 2019

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? A good hash function reduces collisions. Because hash tables work more efficiently when they have fewer collisions, it's important to have a good hash function to reduce the likelihood of collisions
How can you judge if a hash function is good or not? If the function executes in constant time, if it (mostly) maps different keys to different values, it should be consistent, and the hashing should look random.
Is there a perfect hash function? If so what is it? No.
Describe a strategy to handle collisions in a hash table Chaining - we can make each bucket of the hash's internal array the head of a linked list. This isn't great because if there are a lot of items in the same bucket, the time complexity starts to get close to O(n)
Describe a situation where a hash table wouldn't be as useful as a binary search tree If a dataset can't provide unique keys or if you don't really need a key/value pair to search. For example, a really long list of companies in alphabetical order.
What is one thing that is more clear to you on hash tables now Ruby is very kind to us behind the scenes. But now I understand what makes a good hash function, so hopefully I can implement it in other languages.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Really nice, I like how you thought to break down the Sudoku problem into smaller methods. You got all the problems here. Nice work!

# Checks whether there is any
# duplicate in current column or not.
def in_column?(table)

Choose a reason for hiding this comment

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

These in_row and in_column methods don't look very dry here.

end
end

Choose a reason for hiding this comment

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

Minor thing: I suggest a return true here.

# Checks whether there is any duplicate
# in current 3×3 box or not.
def in_box?(table)

Choose a reason for hiding this comment

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

This is a really slick method! Nice

# Space Complexity: ?
# in the case of a tie it will select the first occurring element.
# Time Complexity: O(n)
# Space Complexity: O(n)
def top_k_frequent_elements(list, k)

Choose a reason for hiding this comment

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

Nice work!

# Time Complexity: ?
# Space Complexity: ?
# in the case of a tie it will select the first occurring element.
# Time Complexity: O(n)

Choose a reason for hiding this comment

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

Looking at your later loop, I would say this is O(k * n)

# 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)

Choose a reason for hiding this comment

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

Assuming the words are small, this is correct.

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