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

Branches - Brianna #1

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

Branches - Brianna #1

wants to merge 4 commits into from

Conversation

brikemp
Copy link

@brikemp brikemp commented Mar 14, 2020

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? The distribution of a heap requires a parent's value to always be less/greater than their children, while in a binary search tree a parent with two children will always fall in the middle of the two
Could you build a heap with linked nodes? Yes?...but it wouldn't be as efficient as using an array because you can take advantage of using indexes
Why is adding a node to a heap an O(log n) operation? Because in the worst case scenario you would have to heap up to the top of the heap. A heap is a binary tree, so the number of levels is determined by log n
Were the heap_up & heap_down methods useful? Why? Yes, it simplified the implementation of the public functions. It also helped me to visualize what was actually happening

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.

Nicely done, you hit the learning goals here. Awesome work. Do take a look at my comments on time/space complexity. Otherwise well done.

lib/heapsort.js Outdated
Comment on lines 4 to 7
// Time Complexity: O(log n)
// 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.

You're adding n elements to a heap (each add is log n) and so this sort is O(n log n) time complexity.

lib/minheap.js Outdated
Comment on lines 55 to 57
// 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.

👍

lib/minheap.js Outdated
Comment on lines 80 to 82
// Time complexity: O(log n) - n: nodes in heap
// Space complexity: O(log n) or O(1)?
heapDown(index) {

Choose a reason for hiding this comment

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

For space complexity are you creating any new data structures? Are you making recursive calls? If not it's O(1).

Otherwise this works.

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