Skip to content

C16/Cedar- Ana Gabriele #39

Open
Anagabsoares wants to merge 3 commits intoAda-C16:masterfrom
Anagabsoares:master
Open

C16/Cedar- Ana Gabriele #39
Anagabsoares wants to merge 3 commits intoAda-C16:masterfrom
Anagabsoares:master

Conversation

@Anagabsoares
Copy link
Copy Markdown

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important?
How can you judge if a hash function is good or not?
Is there a perfect hash function? If so what is it?
Describe a strategy to handle collisions in a hash table
Describe a situation where a hash table wouldn't be as useful as a binary search tree
What is one thing that is more clear to you on hash tables now

Copy link
Copy Markdown

@chimerror chimerror left a comment

Choose a reason for hiding this comment

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

Good work!

I left some comments about your time complexity calculation for the anagrams problems, and a few comments about extraneous testing code left in. Otherwise, though, this looks good enough for a Green, so that's what I'm giving it!

Time Complexity: ?
Space Complexity: ?

Time Complexity: O(m * nlogn) - | python sorting algorithm -> O(n. logn).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

While this is an accurate answer assuming n stands for the number of characters in the strings and m stands for the number of strings in the list, we can make a simplifying assumption. Since we know the strings are English words, we can be pretty sure they will not get too big in size. On average words in English have about 5 letters, which is going to very quickly get dwarfed by the number of words in the list so we can simply say this is O(m) in time complexity.

return list(hash_table.values())


print(grouped_anagrams(["eat", "tae", "tea", "eta", "aet", "ate"]))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In general, make sure to remove testing code like this before you submit your PRs.

if len(result) == k:
return result

print(top_k_frequent_elements([9,9,8,8,7],2))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same thing as above, make sure to remove testing code like this. It helps keep the code cleaner which is good style.

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