Skip to content

Conversation

@KayKay-git
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? The BST is an ordered data structure, however, the Heap is not.
Could you build a heap with linked nodes? Yes, but it's easier to implement a heap with an array.
Why is adding a node to a heap an O(log n) operation? Since there are Log n levels to the heap, then adding a node is a O(log n) operation.
Were the heap_up & heap_down methods useful? Why? Yes, it helps to keep the heap organized as it gets re-structured

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.

Get work Kalki, this is quite well done.

# Time Complexity: ?
# Space Complexity: ?
def heap_sort(list)
def heapsort(list)

Choose a reason for hiding this comment

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

Why the rename?

Comment on lines +17 to 19
# Time Complexity: O(log n)
# Space Complexity: O(log 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.

👍 Nice work with the time/space complexity

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

Choose a reason for hiding this comment

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

👍 Nice work with the time/space complexity

Comment on lines +62 to 64
# 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 +74 to 76
# Time complexity: O(log n)
# Space complexity: O(log n)
def heap_up(index)

Choose a reason for hiding this comment

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

👍

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

👍 Nice work with the time/space complexity

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