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

Branches - Kelsey #1

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

Branches - Kelsey #1

wants to merge 3 commits into from

Conversation

kelsk
Copy link

@kelsk kelsk commented Mar 9, 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 is important to keep data secure, contribute to efficient runtime, and avoid collisions.
How can you judge if a hash function is good or not? A hash function is good if it avoids collisions and assigns seemingly random indexes to keys. The more random the assignment, the more secure the data will be.
Is there a perfect hash function? If so what is it? There is not a perfect hash function. Hashing functions are heuristics.
Describe a strategy to handle collisions in a hash table One strategy is linear probing, in which the collision is handled by checking the next adjacent element in the array to see if it's empty, and so on until an empty bucket is found.
Describe a situation where a hash table wouldn't be as useful as a binary search tree A hash table would be less useful if its data wouldn't be able to create unique hash keys.
What is one thing that is more clear to you on hash tables now I understand the concept and purpose of hash functions, which I didn't previously know.

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.

Overall not bad, you've got the solutions, but your sort is O(n^2) for the kth largest, You can use the built-in sort method to do a MergeSort. You did hit the main learning goals here.

Comment on lines +3 to +5
// Time Complexity: O(n) overall. Iterating over the array of strings to extract each string is O(n) where n is the length of the array. Alphabetizing each string is itself O(n) where n is the length of the word. Checking for the key in the uniqAnagrams object is O(1), and inserting an object into an array in Javascript is O(n). Pretty sure Object.keys is an O(n) situation as well.
// Space Complexity: O(n). Creating a hash with a size of up to 'n' length of strings, and creating an array of subarrays with a total size that's up to 'n' length of strings. (Also creating an array 'key' that's the size of the length of one string.)
function groupedAnagrams(strings) {

Choose a reason for hiding this comment

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

Good, but the lines are a bit long to read.

Comment on lines +42 to +46
// Time Complexity: O(n).
// Iterating over 'list' is O(n) where n is the length of 'list', iterating over 'uniqEls' is O(n) where n is the length of uniqEls(less than or equal to the length of 'list').
// Space Complexity: O(n). Creating a hash and an array are both O(n).

function topKFrequentElements(list, k) {

Choose a reason for hiding this comment

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

Given your two nested loops you have an O(n^2) time complexity.

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