Skip to content

Ari#7

Open
aribray wants to merge 5 commits intoAda-C11:masterfrom
aribray:master
Open

Ari#7
aribray wants to merge 5 commits intoAda-C11:masterfrom
aribray:master

Conversation

@aribray
Copy link
Copy Markdown

@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
Copy Markdown

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

Comment thread lib/exercises.rb

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

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.

Comment thread lib/exercises.rb
end
end
end

Copy link
Copy Markdown

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.

Comment thread lib/exercises.rb

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

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

Comment thread lib/exercises.rb
# 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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work!

Comment thread lib/exercises.rb
# Time Complexity: ?
# Space Complexity: ?
# in the case of a tie it will select the first occurring element.
# Time Complexity: O(n)
Copy link
Copy Markdown

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)

Comment thread lib/exercises.rb
# Each subarray will have strings which are anagrams of each other
# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
Copy link
Copy Markdown

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