Skip to content

Conversation

@mulhoo
Copy link

@mulhoo mulhoo commented Sep 30, 2020

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? require left child nodes to be smaller and right ones to be bigger
Could you build a heap with linked nodes? yes, but normally built with an array as the underlying structure
Why is adding a node to a heap an O(log n) operation? tree has oolong levels
Were the heap_up & heap_down methods useful? Why? yes

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.

Overall nice work, but remember that recursion incurs a space complexity and if you are doing recursion you have a loop of sorts (time complexity).

Comment on lines +4 to 6
# Time Complexity: o1
# Space Complexity: on
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 O(1)??? How ❓ ❗

Comment on lines +16 to 18
# Time Complexity:ologn
# Space Complexity: o1
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.

👍 , Since heap_up is a recursive method, you have a space complexity incurred.

Comment on lines +26 to 28
# Time Complexity:ologn
# Space Complexity: o1
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 +54 to 56
# Time complexity: o1
# Space complexity: o1
def empty?

Choose a reason for hiding this comment

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

👍

# Space complexity: ?
# Time complexity: o1
# Space complexity: o1
def heap_up(index)

Choose a reason for hiding this comment

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

👍 , but the time/space complexity is off here.

# This helper method takes an index and
# moves it up the heap if it's smaller
# than it's parent node.
def heap_down(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