-
Notifications
You must be signed in to change notification settings - Fork 0
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
prework questions #6
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great questions and answers!
@@ -0,0 +1,17 @@ | |||
## My questions from the reading | |||
### Heap | |||
* "In order to maintain the heap order property, all we need to do is swap the root with its smallest child less than the root." why the smallest child less than the root? what happens if we swap it with the larger child? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say the smaller child is 2 and the larger child is 4. If you swap the root with the larger child, now you have 4 as the parent of 2, which breaks the heap order property!
## My questions from the reading | ||
### Heap | ||
* "In order to maintain the heap order property, all we need to do is swap the root with its smallest child less than the root." why the smallest child less than the root? what happens if we swap it with the larger child? | ||
* Given the same list of numbers - will the binary heap list be exactly the same regardless of the order in which the numbers are inserted into the heap? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the list could depend on the order that numbers are inserted (the reason is that there are lots of valid heap orderings).
### Heap | ||
* "In order to maintain the heap order property, all we need to do is swap the root with its smallest child less than the root." why the smallest child less than the root? what happens if we swap it with the larger child? | ||
* Given the same list of numbers - will the binary heap list be exactly the same regardless of the order in which the numbers are inserted into the heap? | ||
* "Although we start out in the middle of the tree and work our way back toward the root, the percolate_down method ensures that the largest child is always moved down the tree." I'm not sure what they mean by largest child. largest child of...? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the easiest way to clear this one up is to do an example (either during or after class).
* Given the same list of numbers - will the binary heap list be exactly the same regardless of the order in which the numbers are inserted into the heap? | ||
* "Although we start out in the middle of the tree and work our way back toward the root, the percolate_down method ensures that the largest child is always moved down the tree." I'm not sure what they mean by largest child. largest child of...? | ||
### Binary Tree | ||
* "A balanced binary tree has roughly the same number of nodes in the left and right subtrees of the root" why roughly? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you require "exactly", then that puts too much restriction on the size of the tree.
|
||
## Prework questions | ||
* What are the trade-offs being made between chaining and linear probing? | ||
Linear probing - total memory size for the hash is allocated at the start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point!
Tradeoff - clustering - if a lot of collisions occur around the same hash value, or there are are a few collisions that occur in an already densely-packed area of the hash table, then it degrades to sequential search where you search for the item until you either find it or you find an empty slot. | ||
Chaining - if more than one item hashes to the same slot, make a list and append the item to the list. Advantage is that if the value hashes to slot X and you cannot find it in the list at slot X, it is definitely not there. disadvantage is that if everything hashes to the same value, then you get o(n) to search. degrades back to sequential search. | ||
* Which of these do you think is more commonly used? | ||
Not sure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're both used. For example, Java uses chaining and Ruby uses open addressing
* Which of these do you think is more commonly used? | ||
Not sure | ||
* Considering a hash map that uses chaining, when should the underlying array grow? What about for one that uses linear probing? | ||
When the load factor exceeds a certain amount. Not sure how much and when though. For arrays usually the principle is to double the space needed when the array is full. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! By the way, these conditions are sometimes configurable.
No description provided.