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

Aimee 👾 - Fire 🔥 #1

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

Aimee 👾 - Fire 🔥 #1

wants to merge 4 commits into from

Conversation

marks214
Copy link

@marks214 marks214 commented Apr 12, 2021

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? A good hash function is important because it makes hash tables more efficient by reducing the number of collisions.
How can you judge if a hash function is good or not? A good hash function will be well spaced by spreading elements out over different buckets, and have the least amount of clusters.
Is there a perfect hash function? If so what is it? A perfect hash function would have zero collisions.
Describe a strategy to handle collisions in a hash table A strategy to handle collisions in a hash table would be linear probing. Linear probing inserts an element into the next available bucket if an index is occupied.
Describe a situation where a hash table wouldn't be as useful as a binary search tree When a dataset cannot be mapped with unique keys then a hash table wouldn't be as useful.
What is one thing that is more clear to you on hash tables now I understand that there are several ways that a hash table handles collisions.

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.

Well done Aimee, you hit the learning goals here. Nice work!

Comment on lines +3 to 5
// Time Complexity: O(n^3) - outer while loop (line 10) has a nested for loop (lines 24 and 27), it also has .splice() nested in a for loop, but this should still be O(n^3) overall.
// Space Complexity: O(n) - result, hash, and matched will be at most length n, where n is the number of elements in the strings array. Even though result is a nested array, it will never contain more than n elements.
function grouped_anagrams(strings) {

Choose a reason for hiding this comment

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

Suggestion: Sort the letters in each word and use that as a key to a hash and make the value a list of words with those letters.

Comment on lines +53 to 55
// Time Complexity: O(nlog(n)) - uses javascript sort, where n is the unique number of elements (worst case)
// Space Complexity: O(n) - the hash object will never have more than n number of key-value pairs (based on what elements are in list), and the result array will never have more than n elements, where n is the value of k
function 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.

👍 This will work

Comment on lines +91 to 93
// Time Complexity: O(n)
// Space Complexity: O(n)
function valid_sudoku(table) {

Choose a reason for hiding this comment

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

👍 Fun fact, since a Sudoku board is always 9x9, this problem is actually O(1) !

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