Skip to content

Branches - Brianna#1

Open
brikemp wants to merge 4 commits intoAda-C12:masterfrom
brikemp:master
Open

Branches - Brianna#1
brikemp wants to merge 4 commits intoAda-C12:masterfrom
brikemp:master

Conversation

@brikemp
Copy link
Copy Markdown

@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
Copy Markdown

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

Comment thread lib/heapsort.js Outdated
Comment on lines 4 to 7
// Time Complexity: O(log n)
// Space Complexity: O(n)

function heapsort(list) {
Copy link
Copy Markdown

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.

Comment thread lib/minheap.js
Comment on lines +55 to 57
// Time complexity: O(1)
// Space complexity: O(1)
isEmpty() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/minheap.js
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) {
Copy link
Copy Markdown

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