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

Heather #15

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

Heather #15

wants to merge 2 commits into from

Conversation

piffer59
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? To avoid collision and to ensure O(1) lookup
How can you judge if a hash function is good or not? appears to be random, spreads values of similar keys far apart
Is there a perfect hash function? If so what is it? no
Describe a strategy to handle collisions in a hash table use a linked list at that index, linear probing - if the index that is hashed to is occupied, check the next one
Describe a situation where a hash table wouldn't be as useful as a binary search tree when you want to preserve order, consistent
What is one thing that is more clear to you on hash tables now That their underlying structure is an array

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.

You have both methods working. Nice job! See my notes on the time complexity.

Well done!

@@ -2,29 +2,73 @@

# This method will return an array of arrays.
# Each subarray will have strings which are anagrams of each other
# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: Would this by O(nlog n) for sorting of the string?

Choose a reason for hiding this comment

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

I would say O( n * m log m) where n is the number of words, and m the length of each word. If you can assume that the words are small, then you could say this is O(n)

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: Would this by O(nlog n) for sorting of the string?
# Space Complexity: O(n + m), n is the size of the array and m is the size of the hash

Choose a reason for hiding this comment

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

Since the size of the hash depends on the size of strings I would say O(n)

end

# This method will return the k most common elements
# in the case of a tie it will select the first occuring element.
# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(nlog n) because of the sorted array is at least

Choose a reason for hiding this comment

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

True! Could this be faster without sorting?


answer_arr = []
k.times do

Choose a reason for hiding this comment

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

This looks like a loop that runs k times and a nested loop which runs maybe n times.

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