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

chan.rock #23

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

chan.rock #23

wants to merge 3 commits into from

Conversation

chanbzz
Copy link

@chanbzz chanbzz commented Dec 11, 2021

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? Heaps must maintain the max or min heap property
Could you build a heap with linked nodes? i think so.
Why is adding a node to a heap an O(log n) operation? because when heaping up or down, the added node is only being compared to parents in question and not all of the nodes on the tree
Were the heap_up & heap_down methods useful? Why? they definitely helped with the redunancy of logic in the add and remove methods and also made sorting a list feel like a breeze.

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.

Nice work Chan, you hit the learning goals here. Well done .

heap = MinHeap()

list = [heap.add(num) for num in list]

Choose a reason for hiding this comment

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

Not sure why you have a list comprehension here.

Comment on lines 5 to 9
def heap_sort(list):
""" This method uses a heap to sort an array.
Time Complexity: ?
Space Complexity: ?
Time Complexity: o.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.

👍 The time complexity is O(n log n) and space O(n)

@@ -21,19 +21,33 @@ def __init__(self):
def add(self, key, value = None):

Choose a reason for hiding this comment

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

👍


self.store.append(node)

self.heap_up(len(self.store) - 1)

def remove(self):

Choose a reason for hiding this comment

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

👍

"""
pass
return self.store == []


def heap_up(self, index):

Choose a reason for hiding this comment

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

👍

self.heap_up(parent_index)




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