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

prework questions #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions prework.md
Original file line number Diff line number Diff line change
@@ -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?

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!

* 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?

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).

* "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...?

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).

### Binary Tree
* "A balanced binary tree has roughly the same number of nodes in the left and right subtrees of the root" why roughly?

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

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

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

* 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.

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.