Skip to content

Conversation

@OlgaSe
Copy link

@OlgaSe OlgaSe commented May 3, 2021

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? Because hash tables perform relatively well in terms of big-o and using the hash function is the core functionality for the hash tables.
How can you judge if a hash function is good or not? When hash function is written efficiently, then the lower chances of collisions in a hash map and we want less number of collisions in them. Also, it should be run in constant time, be random, consistent, map different keys to different values.
Is there a perfect hash function? If so what is it? no, a function that could guarantee that no collisions occur doesn't exist.
Describe a strategy to handle collisions in a hash table There are a few strategies: chaining - is to make each bucket the head of the linked list and add each new element in front of it. Linear probing - hash function returns an index where to add a new element, if it's occupied a new element will be placed in the next available bucket. Hash function will be checking all buckets to find the empty one. Quadratic probing - keeps the same approach as linear probing except it's not checking every bucket but the formula is applied to define the next available bucket.
Describe a situation where a hash table wouldn't be as useful as a binary search tree When the data should be sorted and keep the order.
What is one thing that is more clear to you on hash tables now what and why hash function is used for.

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.

Nice work Olga, you hit all the learning goals here. Well done.

Comment on lines +4 to 15
# Time Complexity: O(n * m log m) where n - length of the strings array, m - length of the longest string
# Space Complexity: O(n)

# [eat, meet, tea, ate, hi]

# {
# 'aet' => [eat, tea, ate],
# 'eemt' => [meet],
# 'ih' => [ih]
# }

def grouped_anagrams(strings)

Choose a reason for hiding this comment

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

👍

Comment on lines +36 to 38
# Time Complexity: O(n log 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.

👍

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