Skip to content

Iris Lux - Water#25

Open
iris-lux wants to merge 2 commits intoAda-C14:masterfrom
iris-lux:master
Open

Iris Lux - Water#25
iris-lux wants to merge 2 commits intoAda-C14:masterfrom
iris-lux:master

Conversation

@iris-lux
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 ordered top-to-bottom, binary search tress - left-to-right
Could you build a heap with linked nodes? Yes
Why is adding a node to a heap an O(log n) operation? It potentially has to cycle thru each level of a tree
Were the heap_up & heap_down methods useful? Why? They allow nodes to be added and removed recusrsively.

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

Comment on lines +4 to 6
# Time Complexity: o(nlogn)
# Space Complexity: o(nlogn)
def heap_sort(list)

Choose a reason for hiding this comment

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

👍 The space complexity is O(n) since you are making a Heap with n elements.

Comment on lines +17 to 19
# Time Complexity: O(logn)
# Space Complexity: O(logn)
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 +27 to 29
# Time Complexity: O(logn)
# Space Complexity: O(logn)
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: 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 +65 to +67
# Time complexity: O(logn)
# Space complexity: O(logn)
def heap_up(idx)

Choose a reason for hiding this comment

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

👍

Comment on lines 74 to +79
# 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)
raise NotImplementedError, "Method not implemented yet..."
# Time complexity: O(logn)
# Space complexity: O(logn)
def heap_down(idx)

Choose a reason for hiding this comment

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

👍 Very elegant

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