Skip to content

chan.rock#23

Open
chanbzz wants to merge 3 commits into
Ada-C15:masterfrom
chanbzz:master
Open

chan.rock#23
chanbzz wants to merge 3 commits into
Ada-C15:masterfrom
chanbzz:master

Conversation

@chanbzz
Copy link
Copy Markdown

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

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

Comment thread heaps/heap_sort.py

heap = MinHeap()

list = [heap.add(num) for num in 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.

Not sure why you have a list comprehension here.

Comment thread heaps/heap_sort.py
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
"""
Copy link
Copy Markdown

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)

Comment thread heaps/min_heap.py
@@ -21,19 +21,33 @@ def __init__(self):
def add(self, key, value = None):
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 heaps/min_heap.py

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

def remove(self):
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 heaps/min_heap.py
return self.store == []


def heap_up(self, 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.

👍

Comment thread heaps/min_heap.py



def heap_down(self, 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.

👍

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