Skip to content

Conversation

sarahstandish
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? The only requirement about a node vis a vis its children is that the node must be smaller (min heap) or larger (max heap)
Could you build a heap with linked nodes? Yes, though you might need a different method to find the parent/child nodes.
Why is adding a node to a heap an O(log n) operation? Bc we need to heap down.
Were the heap_up & heap_down methods useful? Why? Yes. The only way to resort nodes.

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! I left some comments on time and space complexity. Let me know what questions you have.

🟢



def heap_sort(list):
def heap_sort(l):

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) where n is the length of self.store (??)
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 job on the time complexity, however space complexity would also be O(log n) because of the recursive call stack created by heap_up

else:
return

def remove(self):

Choose a reason for hiding this comment

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

✨ Time and space complexity?

return f"[{', '.join([str(element) for element in self.store])}]"


def empty(self):

Choose a reason for hiding this comment

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

This could be **very** helpful for the add method.
Time complexity: O(log n) where n is the length of self.store (??)
Space complexity: O(1)

Choose a reason for hiding this comment

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

✨ However because of heap_up's recursive call, space complexity is O(log n).


return removed.value

def heap_down(self, index):

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