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

Tatiana #18

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

Tatiana #18

wants to merge 8 commits into from

Conversation

tatsqui
Copy link

@tatsqui tatsqui commented Sep 18, 2019

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? Because it will guarantee uniqueness MOST of the time, avoid collisions, and thus provide the functionality of storing data with a quick lookup time for a specific value.
How can you judge if a hash function is good or not? If the hash function avoids collisions, and uniformly distrubute values, and thus can provide an O(1) lookup time for most use cases, then it is a good hash function.
Is there a perfect hash function? If so what is it? Nope.
Describe a strategy to handle collisions in a hash table There is linear probing where if there is a collision, you look to the next bucket to see if it is available or not, and then assign the hash key to that bucket to store the value being mapped. Problem with this approach is that it can cause clustering which means the information isn't uniformly distributed within the underlying datat structure.
Describe a situation where a hash table wouldn't be as useful as a binary search tree When you are trying to find a maximum or minimum value, or otherwise trying to search based on ordered data. Hash functions don't care about order.
What is one thing that is more clear to you on hash tables now The heuristic of implementing one is a bit more clear now, although it does still seem like a complicated algorithm to come up with.

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, you hit the learning goals here. Excellent work! Thanks for getting this in.

Comment on lines +5 to +6
# Time Complexity: O(n) it must go through the entire list
# Space Complexity: O(n) we return an array of size n same as the input array

Choose a reason for hiding this comment

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

👍

Comment on lines +50 to +51
return_array.push(sorted_hash_array[i][0])
i += 1

Choose a reason for hiding this comment

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

indentation

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(nLogn)

Choose a reason for hiding this comment

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

where n is the number of distinct elements.

You also should consider that the list might be much longer than the number of distinct elements.

So maybe O(n + k log k) where k is the number of distinct elements and n the number of elements.

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