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

Space - Cathy #14

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

Space - Cathy #14

wants to merge 4 commits into from

Conversation

cojenco
Copy link

@cojenco cojenco commented Sep 14, 2020

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? A good hash function performs relatively well in terms of big O notation (O(1) for searching) and hence is important for quick lookups.
How can you judge if a hash function is good or not? A hash function tends to be better if there are less collisions and a lower load factor.
Is there a perfect hash function? If so what is it? No, there is not a mathematically provable perfect solution.
Describe a strategy to handle collisions in a hash table One way to handle collisions is linear probing, where you insert the value into the next empty bucket in the inner array.
Describe a situation where a hash table wouldn't be as useful as a binary search tree When data needs to be sorted in order, a BST might be more suitable than a hash table.
What is one thing that is more clear to you on hash tables now Ways to handle 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.

Nice work Cathy, you hit the learning goals here. I like your documentation and especially how you implemented top_k_frequent_elements. Well done.

lib/exercises.rb Outdated
Comment on lines 4 to 7
# Time Complexity: O(n^2) where n is the number of strings? || O(n) where n is the total number of characters?
# Space Complexity: O(n) where a new hash is storing the n # of strings

def grouped_anagrams(strings)

Choose a reason for hiding this comment

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

👍 But your time complexity is O(n) since you're only looping through the words once.

Comment on lines +31 to 33
# Time Complexity: O(nlogn) since I'm calling a sort_by enumerable
# 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, good job looking up what max_by does. Well done.

lib/exercises.rb Outdated
Comment on lines 61 to 64
# Reference: https://www.tutorialspoint.com/valid-sudoku-in-python
# Time Complexity: O(n^2) where n is the length of the input table and since table is a 2d array
# Space Complexity: O(1) where the extra hashes are constant tracking 1~9
def valid_sudoku(table)

Choose a reason for hiding this comment

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

👍 Actually since a Sudoku board is always 9x9, scaling never changes so it's O(1) instead of O(n^2)

Comment on lines +103 to +104
# Thought I could use a hash function to solve grouped_anagrams, but realized the sum/math would cause incorrect results
# def grouped_anagrams(strings)

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