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

Ringo - Earth #3

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

Ringo - Earth #3

wants to merge 5 commits into from

Conversation

ringolingo
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important? A good hash function reduces collisions. If a hash has lots of collisions, it loses time efficiency and actions that should be O(1), like look up or addition, can approach O(n).
How can you judge if a hash function is good or not? You can tell if a hash function is not good if the time efficiency drops, meaning it is giving you too many collisions.
Is there a perfect hash function? If so what is it? There is no perfect hash function. A hash function might be more or less suited to a particular set of data, but it cannot guarantee zero collisions nor would it necessarily be as well suited to a different situation.
Describe a strategy to handle collisions in a hash table One strategy to handle collisions is chaining. Instead of one separate element at each array index, there is a linked list. Keys that are directed to the same index are stored as nodes in the linked list. When a hash has to look up one of these keys, it searches through the linked list until it finds the correct one.
Describe a situation where a hash table wouldn't be as useful as a binary search tree Data in a hash is not sorted. If you want to be able to find, add, or delete data based on sorted criteria like highest or lowest, a binary search tree would be better.
What is one thing that is more clear to you on hash tables now I have a clearer understanding now of how a hash is saved in memory and how it is able to find the right spot in memory.

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.

Very well done Ringo, this hits all the learning goals and you also got Sudoku! Well done.

Comment on lines +3 to 9
// Time Complexity: O(n*m log m) where n is the length of strings and
// m is the length of the longest string in the strings array.
// The for loop will run n times. Nested inside of that loop is a
// sort function that will be O(m log m) for strings of length m.
// Space Complexity: O(n). The sortedHash and the returned values array
// will increase in size proportionate to the size of the input.
function 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 on the space/time complexity

Comment on lines +25 to 29
// Time Complexity: O(n log n). The controlling factor is the sort function
// which is O(n log n).
// Space Complexity: O(n). allHash and allKeys will both increase
// linear to the size of list. returnArray will increase with the size of k.
function 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.

👍

Comment on lines +55 to 62
// Time Complexity: O(1). The function does have a nested for loop. However,
// the input is always going to be a nine-by-nine board. The function
// will always have to look at, at most, 81 values one at a time.
// The time complexity does not change with the input but is constant.
// Space Complexity: O(1). The function makes 3 data structure that each,
// worst case scenario, end up holding the same amount of values as in the
// input. However, at most, this will be 81 values, 3 times -- a constant value.
function valid_sudoku(table) {

Choose a reason for hiding this comment

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

👍 Great work identifying the space/time complexity


}

function subgrid_helper(i, j) {

Choose a reason for hiding this comment

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

I love this helper

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