Skip to content

Mariah: Pine#19

Open
mrosman7 wants to merge 3 commits intoAda-C16:masterfrom
mrosman7:master
Open

Mariah: Pine#19
mrosman7 wants to merge 3 commits intoAda-C16:masterfrom
mrosman7:master

Conversation

@mrosman7
Copy link

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 organized at the different levels by priority
Could you build a heap with linked nodes? yes, I think you could but heaps are generally used with arrays
Why is adding a node to a heap an O(log n) operation? because you have to also heap up the element you added
Were the heap_up & heap_down methods useful? Why? yes, they made it easier to keep our heap sorted by priority

Copy link

@kyra-patton kyra-patton left a comment

Choose a reason for hiding this comment

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

💫 Nice work Mariah! I just had a couple comments below. Let me know what questions you have.

🟢

""" This method uses a heap to sort an array.
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(log n)

Choose a reason for hiding this comment

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

✨ Would love to see how you could write heap_sort with the MinHeap class you implemented below as well. Additionally, time complexity is O(n logn) because you are doing heappush/heappop which is a log(n) operation n times.

moves the corresponding element down the heap if it's
larger than either of its children and continues until
the heap property is reestablished.
"""

Choose a reason for hiding this comment

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

Time complexity: ?
Space complexity: ?
Time complexity: O(log n)
Space complexity: O(1)

Choose a reason for hiding this comment

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

✨ Nice iterative solution! The only thing I would say is style wise, I might stick to recursion or iteration across heap_up and heap_down for consistency.

Time complexity: ?
Space complexity: ?
Time complexity: O(1)
Space complexity: O(1)

Choose a reason for hiding this comment

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

Time Complexity: ?
Space Complexity: ?
Time Complexity: O(log n)
Space Complexity: O(1)

Choose a reason for hiding this comment

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

✨ Space complexity is O(log n) here because of the recursive call stack of heap_down

Time Complexity: ?
Space Complexity: ?
Time Complexity: O(log n)
Space Complexity: O(1)

Choose a reason for hiding this comment

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

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