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

FIRE - ALICE D #28

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

Conversation

codeandmorecode
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? We can use them for encryption. It can be very time efficient also.
How can you judge if a hash function is good or not? A hash function is a good one if we have fast computation of the hash value; hash values that are uniformly distributed; keys that are close have hash values that are far apart, and hashing appears to be random (hard to deduce the original object)
Is there a perfect hash function? If so what is it? A hash function that has all the above features is close to being a perfect hash function.
Describe a strategy to handle collisions in a hash table One strategy can be Separate Chaining which essentially just uses a linked list to store the collided keys
Describe a situation where a hash table wouldn't be as useful as a binary search tree Hash tables are not good for finding ordered data. A binary search tree would be better in that case.
What is one thing that is more clear to you on hash tables now It is more clear to me what makes up a good hash function.

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 Alice. I did have a few comments on time complexity. Let me know if you have any questions regarding it. WEll done.

Comment on lines +4 to 7
# Time Complexity: O(n)
# Space Complexity: O(n)

def grouped_anagrams(strings)

Choose a reason for hiding this comment

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

👍 Nice work, just a note if the strings are limited in size, the time complexity is O(n), otherwise it is O(n * m log m) where n is the number of strings and m is the length of the strings.

Comment on lines +29 to 31
# Time Complexity: O(n^2) because of the .sort_by used mid method
# 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.

👍 Because you're sorting the (and not in a loop) your algorithm is O(n log n) because Ruby uses MergeSort internally.

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