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

Water - Christabel #16

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

Water - Christabel #16

wants to merge 3 commits into from

Conversation

cescarez
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? Avoids clumping, saves time and space
How can you judge if a hash function is good or not? If it's basically an array
Is there a perfect hash function? If so what is it? No, or if there is that discussion is above my paygrade
Describe a strategy to handle collisions in a hash table use the next space! or make the location of the collision a bucket/another data structure
Describe a situation where a hash table wouldn't be as useful as a binary search tree when you want to sorted data
What is one thing that is more clear to you on hash tables now oh gosh... I am possible more muddled. I don't know anything anymore

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 Christabel, you hit the learning goals here. Well done.

hashes = []
strings.each do |word|
word_hash = {}
word = word.chars.sort #sort is O(n)?

Choose a reason for hiding this comment

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

Sort is O(n log n), it's mergeSort

Comment on lines +4 to 8
# Time Complexity: O(2nm + p) where n is the length of the list passed to grouped_anagrams, and m represents the number of chars in each string and p is the number of unique char hashes
# == O(nm)
# Space Complexity: Um O(2n) == O(n) since I am creating an array equal to the length of the passed in list and the worst case size for the meta_hash is also the length of the passed in list?

def grouped_anagrams(strings)

Choose a reason for hiding this comment

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

I'd say this is O(n * m log m) where m is the number of chars in each string and n is the length of the array.

Comment on lines +46 to 48
# Time Complexity: O(3n) == O(n) where n is the length of the passed in list
# Space Complexity: O(n) since the worst case is that the elements hash is the full length of the passed in list
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.

This is O(n log n) because sorting is O(n log n)

Comment on lines +74 to 79
# Time Complexity: oh goodness. this is a mean question. I'm going with O(1) since the grid is always 9x9, but let me show my work here...
# O(9) == O(1) for checking for uniqueness in all rows and columns
# O(9) == O(1) for building the 2darray of all subgrid values
# O(9^2) == O(1) for checking for uniqueness in all subgrid values
# Space Complexity: for lack of more confident alternate logic, I'm going with the same answer as above, O(1) since the grid is a fixed size so the worst case for the created row, column, and subgrid hash are all worst case space complexities of O(9) and the array of subgrid values is a fixed size of O(81)
def valid_sudoku(table)

Choose a reason for hiding this comment

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

👍 You are correct that the time/space complexity is 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