Skip to content

Conversation

@Blaine206
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? Heaps are unsorted & BST are ordered
Could you build a heap with linked nodes? I believe you could, but I don't think you'd want to.
Why is adding a node to a heap an O(log n) operation? Because you only have to to heap up half the heap.
Were the heap_up & heap_down methods useful? Why? Yes, but heap down was tough. Having the methods made implementing add & remove easier to create, which in turn made heap sort much cleaner.

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 Blaine, you hit the learning goals here. Well done.

Comment on lines +4 to +6
# Time Complexity: O(n)
# Space Complexity: O(n)
def heapsort(list)

Choose a reason for hiding this comment

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

👍 Time complexity is O(n log n) because you run mamasHeap.add (which takes Log n time) n times. So n * log n = n log n

Comment on lines +17 to 19
# Time Complexity: O(log n)
# Space Complexity: O(n)
def add(key, value = key)

Choose a reason for hiding this comment

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

👍

Comment on lines +29 to 31
# Time Complexity: O(log n)
# Space Complexity: O(n)
def remove()

Choose a reason for hiding this comment

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

👍

Comment on lines +60 to 62
# Time complexity: O(1)
# Space complexity: O(1)
def empty?

Choose a reason for hiding this comment

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

👍

Comment on lines +72 to +74
# Time complexity: O(logn)
# Space complexity: O(n)
def heap_up(index) #index of array, key/val, look at key

Choose a reason for hiding this comment

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

👍

# moves it up the heap if it's smaller
# than it's parent node.
# moves it down the heap, if it's larger than its children.
def heap_down(index)

Choose a reason for hiding this comment

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

👍



################################################
# IGNORE ME! (spiraled)

Choose a reason for hiding this comment

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

ok

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