Skip to content

Conversation

@beauttie
Copy link

@beauttie beauttie commented Apr 22, 2021

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? To have fewer collisions and prevent the time complexity of lookup from approaching O(n)
How can you judge if a hash function is good or not? A good hash function is consistent (maps the same key to the same number), maps different keys to different values and distributes them uniformly across the array, executes in constant time, and difficult to reverse.
Is there a perfect hash function? If so what is it? It does not exist.
Describe a strategy to handle collisions in a hash table Quadratic probing searches for an empty bucket in the array that the hash table is built on by applying a function on each attempt of a search.
Describe a situation where a hash table wouldn't be as useful as a binary search tree When you need to maintain ordered data.
What is one thing that is more clear to you on hash tables now Examples of hash functions

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 work here Beauttie. You hit the learning goals here. Well done.

Comment on lines 4 to 7
# Time Complexity: O(n^2)
# Space Complexity: O(n)

def grouped_anagrams(strings)

Choose a reason for hiding this comment

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

👍 Interesting solution with char.ord This works if you know that all the letters are a-z and roughly the same length. That's because you could end up with two strings of different lengths that have the same sum of characters.

Comment on lines +26 to 28
# 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.

👍 I like the O(n) solution here.

return true
end

def valid_boxes(table)

Choose a reason for hiding this comment

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

I like the helper methods here.

# Space Complexity: ?
# Time Complexity: O(1) because the table has nine rows and columns
# Space Complexity: O(1) because each hash will store up to nine cells
def valid_sudoku(table)

Choose a reason for hiding this comment

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

👍

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