Skip to content

Wrote grouped_anagrams method.#1

Open
dev-elle-up wants to merge 4 commits intoAda-C11:masterfrom
dev-elle-up:master
Open

Wrote grouped_anagrams method.#1
dev-elle-up wants to merge 4 commits intoAda-C11:masterfrom
dev-elle-up:master

Conversation

@dev-elle-up
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? Having a good hash function makes this data structure fast - O(1), ideally.
How can you judge if a hash function is good or not? A good hash functions will: disburse items broadly across the internal array (to have a low density), reducing collisions; make it look like it's random; give very different indices for similar keys; be fast; be consistent.
Is there a perfect hash function? If so what is it? No, there is not.
Describe a strategy to handle collisions in a hash table One strategy to handle collisions in linear probing. When a collision happens, the hash function checks the next index in the internal array (bucket) until it finds an empty space.
Describe a situation where a hash table wouldn't be as useful as a binary search tree Hash tables do not keep track of an order for the items they store. Therefore, a binary search tree is a better solution for any situation in which order matters.
What is one thing that is more clear to you on hash tables now Hashes are using a function to convert a key to an index in an array where the value is stored. This is used both to store and to retrieve the value. Who knew?? So cool. 😎 Knowing this makes it all make sense and helped me connect all the dots.

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 goal of this exercise. Well done.

});

describe.skip("valid sudoku", function() {
it("is not valid if a row has duplicate values", function() {

Choose a reason for hiding this comment

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

I'll add this to my set of tests

function grouped_anagrams(strings) {
throw new Error("Method hasn't been implemented yet!");
// Time Complexity: O(n) where n is the length of the array passed in as the argument "strings" because each item in the array is visited once
// Space Complexity: O(1) (***Chris, is this right? It takes 2 times the space of 'strings' which reduces to 1. Or is it O(n) because the space taken is is 2 x n where n is the length of the 'strings' array?***)

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) because you are building a JavaScript object which scales based on the size of the array.


strings.forEach(str => {
let tempStr = str.split('').sort().join(''); // alphabetize str
anagrams[tempStr] ? anagrams[tempStr].push(str) : anagrams[tempStr] = [str];

Choose a reason for hiding this comment

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

Good use of a ternary.

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

Comments