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

Earth - Emily #3

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

Earth - Emily #3

wants to merge 6 commits into from

Conversation

emirry
Copy link

@emirry emirry commented May 3, 2021

Not finished!
Would like some feedback on what is causing my last test in heapsort to fail. I realize there's something wrong with my heapDown(index) method in minheap.

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? A heap is different from a BST in how it's ordered. Depending on whether it's a minheap or maxheap, the parent node will be either smaller or greater than its children. In a BST, all the nodes on the left point to nodes that are smaller than the root, and greater on the right.
Could you build a heap with linked nodes? You can, but it'll be easier to build with an array?
Why is adding a node to a heap an O(log n) operation? Adding a node to a heap is an O(log n) operation, because in worst-case, we're always swapping with 1 node per level, with log n levels. We're also working with only half of the structure.
Were the heap_up & heap_down methods useful? Why? Yes, they were needed to complete the add and remove functions.

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.

Overall nice work Emily. I had one comment on heap-down, but otherwise solid work.

Comment on lines +4 to 7
// Time Complexity: O(nlogn)?
// Space Complexity: O(n)?

function heapsort(list) {

Choose a reason for hiding this comment

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

👍 Very clean!

Correct time/space complexity. No need for question marks!

Comment on lines +26 to 28
// Time Complexity: O(logn)?
// Space Complexity: 0(1)?
remove() {

Choose a reason for hiding this comment

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

👍

Comment on lines +53 to 55
// Time complexity: O(1)
// Space complexity: O(1)
isEmpty() {

Choose a reason for hiding this comment

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

👍

Comment on lines +62 to 64
// Time complexity: O(1) Because we're only swapping??
// Space complexity: O(1)?
heapUp(index) {

Choose a reason for hiding this comment

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

You're doing recursion so the time complexity is O(log n) and space complexity is the same (system stack).

}

this.swap(index, parent);
this.heapUp(parent);
}

// This helper method takes an index and
// moves it up the heap if it's smaller
// than it's parent node.
heapDown(index) {

Choose a reason for hiding this comment

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

What about the situation if there is no right child, but there is a left child?

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